Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.20.2.6
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.5 2024/02/29 21:43:33 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;
1510: }
1.406.2.20.2. (raeburn 1511:): if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
1512:): my @toggles;
1513:): if (&Apache::lonnet::allowed('cau',$ccdomain)) {
1514:): my ($isadv,$isauthor) =
1515:): &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1516:): unless ($isauthor) {
1517:): push(@toggles,'requestauthor');
1518:): }
1519:): push(@toggles,('webdav','editors','archive'));
1520:): }
1521:): if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1522:): push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
1523:): }
1524:): if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1525:): push(@toggles,('official','unofficial','community','textbook'));
1526:): }
1527:): if (@toggles) {
1528:): my $onload;
1529:): foreach my $item (@toggles) {
1530:): $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
1531:): }
1532:): $args->{'add_entries'} = {
1533:): 'onload' => $onload,
1534:): };
1535:): }
1536:): }
1.351 raeburn 1537: my $start_page =
1538: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1539:
1.25 matthew 1540: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1541: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1542: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1543: <input type="hidden" name="ccuname" value="$ccuname" />
1544: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1545: <input type="hidden" name="pres_value" value="" />
1546: <input type="hidden" name="pres_type" value="" />
1547: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1548: ENDFORMINFO
1.375 raeburn 1549: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1550: if ($context eq 'course') {
1551: $inccourses{$env{'request.course.id'}}=1;
1552: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1553: if ($showcredits) {
1554: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1555: }
1.329 raeburn 1556: } elsif ($context eq 'author') {
1557: $roledom = $env{'request.role.domain'};
1558: } elsif ($context eq 'domain') {
1559: foreach my $key (keys(%env)) {
1560: $roledom = $env{'request.role.domain'};
1561: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1562: $inccourses{$1.'_'.$2}=1;
1563: }
1564: }
1565: } else {
1566: foreach my $key (keys(%env)) {
1567: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1568: $inccourses{$1.'_'.$2}=1;
1569: }
1.2 www 1570: }
1.24 matthew 1571: }
1.389 bisitz 1572: my $title = '';
1.406.2.20.2. (raeburn 1573:): my $need_quota_js;
1.216 raeburn 1574: if ($newuser) {
1.406.2.9 raeburn 1575: my ($portfolioform,$domroleform);
1.267 raeburn 1576: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1577: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1578: # Current user has quota or user tools modification privileges
1.406.2.20.2. (raeburn 1579:): $portfolioform = '<br /><h3>'.
1580:): &mt('User Tools').
1581:): '</h3>'."\n".
1582:): &Apache::loncommon::start_data_table();
1583:): if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1584:): $portfolioform .= &build_tools_display($ccuname,$ccdomain,'tools');
1585:): }
1586:): if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
1587:): $portfolioform .= &user_quotas($ccuname,$ccdomain,'portfolio');
1588:): $need_quota_js = 1;
1589:): }
1590:): $portfolioform .= &Apache::loncommon::end_data_table();
1.134 raeburn 1591: }
1.383 raeburn 1592: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1593: ($ccdomain eq $env{'request.role.domain'})) {
1.406.2.20.2. (raeburn 1594:): $domroleform = &domainrole_req($ccuname,$ccdomain).
1595:): &authoring_defaults($ccuname,$ccdomain);
1596:): $need_quota_js = 1;
1597:): }
1598:): my $readonly;
1599:): unless ($permission->{'cusr'}) {
1600:): $readonly = 1;
1.362 raeburn 1601: }
1.406.2.20.2. (raeburn 1602:): &initialize_authen_forms($ccdomain,$formname,'','',$readonly);
1.188 raeburn 1603: my %lt=&Apache::lonlocal::texthash(
1604: 'lg' => 'Login Data',
1.190 raeburn 1605: 'hs' => "Home Server",
1.188 raeburn 1606: );
1.185 raeburn 1607: $r->print(<<ENDTITLE);
1.110 albertel 1608: $start_page
1.160 raeburn 1609: $response
1.25 matthew 1610: $forminfo
1.31 matthew 1611: <script type="text/javascript" language="Javascript">
1.301 bisitz 1612: // <![CDATA[
1.20 harris41 1613: $loginscript
1.301 bisitz 1614: // ]]>
1.31 matthew 1615: </script>
1.20 harris41 1616: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1617: ENDTITLE
1.213 raeburn 1618: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1619: if ($crstype eq 'Community') {
1.389 bisitz 1620: $title = &mt('Create New User [_1] in domain [_2] as a member',
1621: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1622: } else {
1.389 bisitz 1623: $title = &mt('Create New User [_1] in domain [_2] as a student',
1624: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1625: }
1.389 bisitz 1626: } else {
1627: $title = &mt('Create New User [_1] in domain [_2]',
1628: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1629: }
1.389 bisitz 1630: $r->print('<h2>'.$title.'</h2>'."\n");
1631: $r->print('<div class="LC_left_float">');
1.393 raeburn 1632: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1.406.2.20.2. (raeburn 1633:): $inst_results{$ccuname.':'.$ccdomain},$readonly));
1.393 raeburn 1634: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1635: my ($home_server_pick,$numlib) =
1636: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1637: 'default','hide');
1638: if ($numlib > 1) {
1639: $r->print("
1.185 raeburn 1640: <br />
1.187 raeburn 1641: $lt{'hs'}: $home_server_pick
1642: <br />");
1643: } else {
1644: $r->print($home_server_pick);
1645: }
1.304 raeburn 1646: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1647: $r->print('<br /><h3>'.
1.406.2.20.2. (raeburn 1648:): &mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1649: &Apache::loncommon::start_data_table().
1650: &build_tools_display($ccuname,$ccdomain,
1651: 'requestcourses').
1652: &Apache::loncommon::end_data_table());
1653: }
1.188 raeburn 1654: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1655: $lt{'lg'}.'</h3>');
1.185 raeburn 1656: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1657: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1658: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1659: my ($rules,$ruleorder) =
1660: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1661: if (ref($rules) eq 'HASH') {
1.193 raeburn 1662: if (ref($rules->{$matchedrule}) eq 'HASH') {
1663: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1664: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1665: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1666: } else {
1.193 raeburn 1667: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1668: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1669: if ($authtype =~ /^krb(4|5)$/) {
1670: my $ver = $1;
1671: if ($authparm ne '') {
1672: $fixedauth = <<"KERB";
1673: <input type="hidden" name="login" value="krb" />
1674: <input type="hidden" name="krbver" value="$ver" />
1675: <input type="hidden" name="krbarg" value="$authparm" />
1676: KERB
1677: }
1678: } else {
1679: $fixedauth =
1680: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1681: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1682: $fixedauth .=
1683: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1684: } else {
1.273 raeburn 1685: if ($authtype eq 'int') {
1686: $varauth = '<br />'.
1.301 bisitz 1687: &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 1688: } elsif ($authtype eq 'loc') {
1689: $varauth = '<br />'.
1690: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1691: } else {
1692: $varauth =
1.185 raeburn 1693: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1694: }
1.185 raeburn 1695: }
1696: }
1697: }
1698: } else {
1.190 raeburn 1699: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1700: }
1701: }
1702: if ($authmsg) {
1703: $r->print(<<ENDAUTH);
1704: $fixedauth
1705: $authmsg
1706: $varauth
1707: ENDAUTH
1708: }
1709: } else {
1.190 raeburn 1710: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1711: }
1.406.2.9 raeburn 1712: $r->print($portfolioform.$domroleform);
1.215 raeburn 1713: if ($env{'form.action'} eq 'singlestudent') {
1714: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1715: $permission,$crstype,$ccuname,
1716: $ccdomain,$showcredits));
1.215 raeburn 1717: }
1718: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1719: } else { # user already exists
1.389 bisitz 1720: $r->print($start_page.$forminfo);
1.213 raeburn 1721: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1722: if ($crstype eq 'Community') {
1.389 bisitz 1723: $title = &mt('Enroll one member: [_1] in domain [_2]',
1724: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1725: } else {
1.389 bisitz 1726: $title = &mt('Enroll one student: [_1] in domain [_2]',
1727: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1728: }
1.213 raeburn 1729: } else {
1.406.2.6 raeburn 1730: if ($permission->{'cusr'}) {
1731: $title = &mt('Modify existing user: [_1] in domain [_2]',
1732: '"'.$ccuname.'"','"'.$ccdomain.'"');
1733: } else {
1734: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1735: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1736: }
1.213 raeburn 1737: }
1.389 bisitz 1738: $r->print('<h2>'.$title.'</h2>'."\n");
1739: $r->print('<div class="LC_left_float">');
1.393 raeburn 1740: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1741: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1742: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1743: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.406.2.20.2. (raeburn 1744:): $r->print('<br /><h3>'.&mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n".
1.300 raeburn 1745: &Apache::loncommon::start_data_table());
1.314 raeburn 1746: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1747: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1748: } else {
1749: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1750: $env{'request.role.domain'}));
1751: }
1752: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1753: }
1.199 raeburn 1754: $r->print('</div>');
1.406.2.20.2. (raeburn 1755:): my @order = ('auth','quota','tools','requestauthor','authordefaults');
1.362 raeburn 1756: my %user_text;
1757: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1758: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.406.2.20.2. (raeburn 1759:): if (((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1.406.2.6 raeburn 1760: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.406.2.20.2. (raeburn 1761:): ($env{'request.role.domain'} eq $ccdomain)) {
1762:): if (!$isauthor) {
1763:): $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1764:): }
1765:): $user_text{'authordefaults'} = &authoring_defaults($ccuname,$ccdomain);
1766:): if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1767:): $need_quota_js = 1;
1768:): }
1.362 raeburn 1769: }
1.406.2.17 raeburn 1770: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1771: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1772: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1773: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.406.2.20.2. (raeburn 1774:): $user_text{'quota'} = '<br /><h3>'.&mt('User Tools').'</h3>'."\n".
1775:): &Apache::loncommon::start_data_table();
1776:): if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
1777:): (&Apache::lonnet::allowed('udp',$ccdomain))) {
1778:): $user_text{'quota'} .= &build_tools_display($ccuname,$ccdomain,'tools');
1779:): }
1.188 raeburn 1780: # Current user has quota modification privileges
1.406.2.20.2. (raeburn 1781:): if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1782:): (&Apache::lonnet::allowed('udp',$ccdomain))) {
1783:): $user_text{'quota'} .= &user_quotas($ccuname,$ccdomain,'portfolio');
1784:): $need_quota_js = 1;
1785:): }
1786:): $user_text{'quota'} .= &Apache::loncommon::end_data_table();
1.267 raeburn 1787: }
1788: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1789: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1790: my %lt=&Apache::lonlocal::texthash(
1.406.2.20.2. (raeburn 1791:): 'dska' => "Disk quotas for user's portfolio",
1792:): 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1.267 raeburn 1793: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1794: );
1.362 raeburn 1795: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1796: <h3>$lt{'dska'}</h3>
1797: $lt{'youd'} $lt{'ichr'}: $ccdomain
1798: ENDNOPORTPRIV
1.267 raeburn 1799: }
1800: }
1801: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1802: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1803: my %lt=&Apache::lonlocal::texthash(
1804: 'utav' => "User Tools Availability",
1.406.2.20.2. (raeburn 1805:): 'yodo' => "You do not have privileges to modify Portfolio, Blog, Personal Information Page, or Time Zone settings for this user.",
1.267 raeburn 1806: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1807: );
1.362 raeburn 1808: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1809: <h3>$lt{'utav'}</h3>
1810: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1811: ENDNOTOOLSPRIV
1812: }
1.188 raeburn 1813: }
1.362 raeburn 1814: my $gotdiv = 0;
1815: foreach my $item (@order) {
1816: if ($user_text{$item} ne '') {
1817: unless ($gotdiv) {
1818: $r->print('<div class="LC_left_float">');
1819: $gotdiv = 1;
1820: }
1821: $r->print('<br />'.$user_text{$item});
1822: }
1823: }
1824: if ($env{'form.action'} eq 'singlestudent') {
1825: unless ($gotdiv) {
1826: $r->print('<div class="LC_left_float">');
1.213 raeburn 1827: }
1.375 raeburn 1828: my $credits;
1829: if ($showcredits) {
1830: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1831: if ($credits eq '') {
1832: $credits = $defaultcredits;
1833: }
1834: }
1.374 raeburn 1835: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1836: $permission,$crstype,$ccuname,
1837: $ccdomain,$showcredits));
1.374 raeburn 1838: }
1.362 raeburn 1839: if ($gotdiv) {
1840: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1841: }
1.406.2.6 raeburn 1842: my $statuses;
1843: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1844: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1845: $statuses = ['active'];
1846: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1847: ($env{'request.course.sec'} &&
1848: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1849: $statuses = ['active'];
1850: }
1.217 raeburn 1851: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1852: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1853: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1854: }
1.25 matthew 1855: } ## End of new user/old user logic
1.218 raeburn 1856: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1857: my $btntxt;
1858: if ($crstype eq 'Community') {
1859: $btntxt = &mt('Enroll Member');
1860: } else {
1861: $btntxt = &mt('Enroll Student');
1862: }
1863: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1864: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1865: $r->print('<div class="LC_left_float">'.
1866: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1867: my $addrolesdisplay = 0;
1868: if ($context eq 'domain' || $context eq 'author') {
1869: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1870: }
1871: if ($context eq 'domain') {
1.357 raeburn 1872: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1873: if (!$addrolesdisplay) {
1874: $addrolesdisplay = $add_domainroles;
1.2 www 1875: }
1.375 raeburn 1876: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1877: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1878: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1879: } elsif ($context eq 'author') {
1880: if ($addrolesdisplay) {
1.393 raeburn 1881: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1882: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1883: if ($newuser) {
1.301 bisitz 1884: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1885: } else {
1.406.2.20.2. (raeburn 1886:): $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1887: }
1.188 raeburn 1888: } else {
1.393 raeburn 1889: $r->print('</fieldset></div>'.
1890: '<div class="LC_clear_float_footer"></div>'.
1891: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1892: &mt('Back to previous page').'</a>');
1.188 raeburn 1893: }
1894: } else {
1.375 raeburn 1895: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1896: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1897: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1898: }
1.88 raeburn 1899: }
1.188 raeburn 1900: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1901: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1902: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.406.2.20.2. (raeburn 1903:): if ($need_quota_js) {
1904:): $r->print(&user_quota_js());
1905:): }
1.218 raeburn 1906: return;
1.2 www 1907: }
1.1 www 1908:
1.213 raeburn 1909: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1910: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1911: my %breadcrumb_text;
1912: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1913: if ($crstype eq 'Community') {
1914: $breadcrumb_text{'search'} = 'Enroll a member';
1915: } else {
1916: $breadcrumb_text{'search'} = 'Enroll a student';
1917: }
1.406.2.7 raeburn 1918: $breadcrumb_text{'userpicked'} = 'Select a user';
1919: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1920: } elsif ($env{'form.action'} eq 'accesslogs') {
1921: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1922: $breadcrumb_text{'userpicked'} = 'Select a user';
1923: $breadcrumb_text{'activity'} = 'Activity';
1924: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1925: (!&Apache::lonnet::allowed('mau',$domain))) {
1926: $breadcrumb_text{'search'} = "View user's roles";
1927: $breadcrumb_text{'userpicked'} = 'Select a user';
1928: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1929: } else {
1.229 raeburn 1930: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1931: $breadcrumb_text{'userpicked'} = 'Select a user';
1932: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1933: }
1934: return %breadcrumb_text;
1935: }
1936:
1937: sub date_sections_select {
1.375 raeburn 1938: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1939: $showcredits) = @_;
1940: my $credits;
1941: if ($showcredits) {
1942: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1943: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1944: if ($credits eq '') {
1945: $credits = $defaultcredits;
1946: }
1947: }
1.213 raeburn 1948: my $cid = $env{'request.course.id'};
1949: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1950: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1951: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1952: undef,$formname,$permission);
1953: my $rowtitle = 'Section';
1.375 raeburn 1954: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1955: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1956: $permission,$context,'',$crstype,
1957: $showcredits,$credits);
1.213 raeburn 1958: my $output = $date_table.$secbox;
1959: return $output;
1960: }
1961:
1.216 raeburn 1962: sub validation_javascript {
1.375 raeburn 1963: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.406.2.20.2. (raeburn 1964:): $loaditem,$permission) = @_;
1.216 raeburn 1965: my $dc_setcourse_code = '';
1966: my $nondc_setsection_code = '';
1967: if ($context eq 'domain') {
1.406.2.20.2. (raeburn 1968:): if ((ref($permission) eq 'HASH') && ($permission->{'cusr'})) {
1969:): my $dcdom = $env{'request.role.domain'};
1970:): $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1971:): $dc_setcourse_code =
1972:): &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1973:): }
1.216 raeburn 1974: } else {
1.227 raeburn 1975: my $checkauth;
1976: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1977: $checkauth = 1;
1978: }
1979: if ($context eq 'course') {
1980: $nondc_setsection_code =
1981: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1982: undef,$checkauth,
1983: $crstype);
1.227 raeburn 1984: }
1985: if ($checkauth) {
1986: $nondc_setsection_code .=
1987: &Apache::lonuserutils::verify_authen($formname,$context);
1988: }
1.216 raeburn 1989: }
1990: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1991: $nondc_setsection_code,$groupslist);
1992: my ($jsback,$elements) = &crumb_utilities();
1993: $js .= "\n".
1.301 bisitz 1994: '<script type="text/javascript">'."\n".
1995: '// <![CDATA['."\n".
1996: $jsback."\n".
1997: '// ]]>'."\n".
1998: '</script>'."\n";
1.216 raeburn 1999: return $js;
2000: }
2001:
1.217 raeburn 2002: sub display_existing_roles {
1.375 raeburn 2003: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 2004: $showcredits,$statuses) = @_;
1.329 raeburn 2005: my $now=time;
1.406.2.6 raeburn 2006: my $showall = 1;
2007: my ($showexpired,$showactive);
2008: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
2009: $showall = 0;
2010: if (grep(/^expired$/,@{$statuses})) {
2011: $showexpired = 1;
2012: }
2013: if (grep(/^active$/,@{$statuses})) {
2014: $showactive = 1;
2015: }
2016: if ($showexpired && $showactive) {
2017: $showall = 1;
2018: }
2019: }
1.329 raeburn 2020: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 2021: 'rer' => "Existing Roles",
2022: 'rev' => "Revoke",
2023: 'del' => "Delete",
2024: 'ren' => "Re-Enable",
2025: 'rol' => "Role",
2026: 'ext' => "Extent",
1.375 raeburn 2027: 'crd' => "Credits",
1.217 raeburn 2028: 'sta' => "Start",
2029: 'end' => "End",
2030: );
1.329 raeburn 2031: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
2032: if ($context eq 'course' || $context eq 'author') {
2033: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
2034: my %roleshash =
2035: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
2036: ['active','previous','future'],\@roles,$roledom,1);
2037: foreach my $key (keys(%roleshash)) {
2038: my ($start,$end) = split(':',$roleshash{$key});
2039: next if ($start eq '-1' || $end eq '-1');
2040: my ($rnum,$rdom,$role,$sec) = split(':',$key);
2041: if ($context eq 'course') {
2042: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
2043: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
2044: } elsif ($context eq 'author') {
1.406.2.20.2. (raeburn 2045:): if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2046:): my ($audom,$auname) = ($1,$2);
2047:): next unless (($rnum eq $auname) && ($rdom eq $audom));
2048:): } else {
2049:): next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
2050:): }
1.329 raeburn 2051: }
2052: my ($newkey,$newvalue,$newrole);
2053: $newkey = '/'.$rdom.'/'.$rnum;
2054: if ($sec ne '') {
2055: $newkey .= '/'.$sec;
2056: }
2057: $newvalue = $role;
2058: if ($role =~ /^cr/) {
2059: $newrole = 'cr';
2060: } else {
2061: $newrole = $role;
2062: }
2063: $newkey .= '_'.$newrole;
2064: if ($start ne '' && $end ne '') {
2065: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 2066: } elsif ($end ne '') {
2067: $newvalue .= '_'.$end;
1.329 raeburn 2068: }
2069: $rolesdump{$newkey} = $newvalue;
2070: }
2071: } else {
1.360 raeburn 2072: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 2073: }
2074: # Build up table of user roles to allow revocation and re-enabling of roles.
2075: my ($tmp) = keys(%rolesdump);
2076: return if ($tmp =~ /^(con_lost|error)/i);
2077: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
2078: my $b1=join('_',(split('_',$b))[1,0]);
2079: return $a1 cmp $b1;
2080: } keys(%rolesdump)) {
2081: next if ($area =~ /^rolesdef/);
2082: my $envkey=$area;
2083: my $role = $rolesdump{$area};
2084: my $thisrole=$area;
2085: $area =~ s/\_\w\w$//;
2086: my ($role_code,$role_end_time,$role_start_time) =
2087: split(/_/,$role);
1.406.2.6 raeburn 2088: my $active=1;
2089: $active=0 if (($role_end_time) && ($now>$role_end_time));
2090: if ($active) {
2091: next unless($showall || $showactive);
2092: } else {
2093: next unless($showall || $showexpired);
2094: }
1.217 raeburn 2095: # Is this a custom role? Get role owner and title.
1.329 raeburn 2096: my ($croleudom,$croleuname,$croletitle)=
2097: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
2098: my $allowed=0;
2099: my $delallowed=0;
2100: my $sortkey=$role_code;
2101: my $class='Unknown';
1.375 raeburn 2102: my $credits='';
1.406.2.6 raeburn 2103: my $csec;
1.406.2.7 raeburn 2104: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 2105: $class='Course';
2106: my ($coursedom,$coursedir) = ($1,$2);
2107: my $cid = $1.'_'.$2;
2108: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 2109: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 2110: my %coursedata=
2111: &Apache::lonnet::coursedescription($cid);
2112: if ($coursedir =~ /^$match_community$/) {
2113: $class='Community';
2114: }
2115: $sortkey.="\0$coursedom";
2116: my $carea;
2117: if (defined($coursedata{'description'})) {
2118: $carea=$coursedata{'description'}.
2119: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
2120: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
2121: $sortkey.="\0".$coursedata{'description'};
2122: } else {
2123: if ($class eq 'Community') {
2124: $carea=&mt('Unavailable community').': '.$area;
2125: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 2126: } else {
2127: $carea=&mt('Unavailable course').': '.$area;
2128: $sortkey.="\0".&mt('Unavailable course').': '.$area;
2129: }
1.329 raeburn 2130: }
2131: $sortkey.="\0$coursedir";
2132: $inccourses->{$cid}=1;
1.375 raeburn 2133: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
2134: my $defaultcredits = $coursedata{'internal.defaultcredits'};
2135: $credits =
2136: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
2137: $coursedom,$coursedir);
2138: if ($credits eq '') {
2139: $credits = $defaultcredits;
2140: }
2141: }
1.329 raeburn 2142: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
2143: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2144: $allowed=1;
2145: }
2146: unless ($allowed) {
1.365 raeburn 2147: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 2148: if ($isowner) {
2149: if (($role_code eq 'co') && ($class eq 'Community')) {
2150: $allowed = 1;
2151: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
2152: $allowed = 1;
2153: }
1.217 raeburn 2154: }
1.329 raeburn 2155: }
2156: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
2157: (&Apache::lonnet::allowed('dro',$ccdomain))) {
2158: $delallowed=1;
2159: }
1.217 raeburn 2160: # - custom role. Needs more info, too
1.329 raeburn 2161: if ($croletitle) {
2162: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
2163: $allowed=1;
2164: $thisrole.='.'.$role_code;
1.217 raeburn 2165: }
1.329 raeburn 2166: }
1.406.2.6 raeburn 2167: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
2168: $csec = $2;
2169: $carea.='<br />'.&mt('Section: [_1]',$csec);
2170: $sortkey.="\0$csec";
1.329 raeburn 2171: if (!$allowed) {
1.406.2.6 raeburn 2172: if ($env{'request.course.sec'} eq $csec) {
2173: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 2174: $allowed = 1;
1.217 raeburn 2175: }
2176: }
2177: }
1.329 raeburn 2178: }
2179: $area=$carea;
2180: } else {
2181: $sortkey.="\0".$area;
2182: # Determine if current user is able to revoke privileges
2183: if ($area=~m{^/($match_domain)/}) {
2184: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
2185: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2186: $allowed=1;
1.217 raeburn 2187: }
1.329 raeburn 2188: if (((&Apache::lonnet::allowed('dro',$1)) ||
2189: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
2190: ($role_code ne 'dc')) {
2191: $delallowed=1;
1.217 raeburn 2192: }
1.329 raeburn 2193: } else {
2194: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 2195: $allowed=1;
2196: }
2197: }
1.363 raeburn 2198: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 2199: $class='Authoring Space';
1.329 raeburn 2200: } elsif ($role_code eq 'su') {
2201: $class='System';
1.217 raeburn 2202: } else {
1.329 raeburn 2203: $class='Domain';
1.217 raeburn 2204: }
1.329 raeburn 2205: }
2206: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
2207: $area=~m{/($match_domain)/($match_username)};
2208: if (&Apache::lonuserutils::authorpriv($2,$1)) {
2209: $allowed=1;
1.406.2.20.2. (raeburn 2210:): } elsif (&Apache::lonuserutils::coauthorpriv($2,$1)) {
2211:): $allowed=1;
1.217 raeburn 2212: } else {
1.329 raeburn 2213: $allowed=0;
1.217 raeburn 2214: }
1.329 raeburn 2215: }
2216: my $row = '';
1.406.2.6 raeburn 2217: if ($showall) {
2218: $row.= '<td>';
2219: if (($active) && ($allowed)) {
2220: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 2221: } else {
1.406.2.6 raeburn 2222: if ($active) {
2223: $row.=' ';
2224: } else {
2225: $row.=&mt('expired or revoked');
2226: }
1.217 raeburn 2227: }
1.406.2.6 raeburn 2228: $row.='</td><td>';
2229: if ($allowed && !$active) {
2230: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
2231: } else {
2232: $row.=' ';
2233: }
2234: $row.='</td><td>';
2235: if ($delallowed) {
2236: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
2237: } else {
2238: $row.=' ';
2239: }
2240: $row.= '</td>';
1.329 raeburn 2241: }
2242: my $plaintext='';
2243: if (!$croletitle) {
1.375 raeburn 2244: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
2245: if (($showcredits) && ($credits ne '')) {
2246: $plaintext .= '<br/ ><span class="LC_nobreak">'.
2247: '<span class="LC_fontsize_small">'.
2248: &mt('Credits: [_1]',$credits).
2249: '</span></span>';
2250: }
1.329 raeburn 2251: } else {
2252: $plaintext=
1.395 bisitz 2253: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 2254: '"'.$croletitle.'"',
2255: '<br />',
2256: $croleuname.':'.$croleudom);
1.329 raeburn 2257: }
1.406.2.6 raeburn 2258: $row.= '<td>'.$plaintext.'</td>'.
2259: '<td>'.$area.'</td>'.
2260: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
2261: : ' ' ).'</td>'.
2262: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
2263: : ' ' ).'</td>';
1.329 raeburn 2264: $sortrole{$sortkey}=$envkey;
2265: $roletext{$envkey}=$row;
2266: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 2267: if ($allowed) {
2268: $rolepriv{$envkey}='edit';
2269: } else {
2270: if ($context eq 'domain') {
1.406.2.7 raeburn 2271: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
2272: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 2273: $rolepriv{$envkey}='view';
2274: }
2275: } elsif ($context eq 'course') {
2276: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2277: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2278: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2279: $rolepriv{$envkey}='view';
2280: }
2281: }
2282: }
1.329 raeburn 2283: } # end of foreach (table building loop)
2284:
2285: my $rolesdisplay = 0;
2286: my %output = ();
1.377 raeburn 2287: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2288: $output{$type} = '';
2289: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2290: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2291: $output{$type}.=
2292: &Apache::loncommon::start_data_table_row().
2293: $roletext{$sortrole{$which}}.
2294: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2295: }
1.329 raeburn 2296: }
2297: unless($output{$type} eq '') {
2298: $output{$type} = '<tr class="LC_info_row">'.
2299: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2300: $output{$type};
2301: $rolesdisplay = 1;
2302: }
2303: }
2304: if ($rolesdisplay == 1) {
2305: my $contextrole='';
2306: if ($env{'request.course.id'}) {
2307: if (&Apache::loncommon::course_type() eq 'Community') {
2308: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2309: } else {
1.329 raeburn 2310: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2311: }
1.329 raeburn 2312: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2313: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.406.2.20.2. (raeburn 2314:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)/$}) {
2315:): $contextrole = &mt('Existing Co-Author Roles in [_1] Authoring Space',
2316:): '<i>'.$1.'_'.$2.'</i>');
1.329 raeburn 2317: } else {
1.406.2.6 raeburn 2318: if ($showall) {
2319: $contextrole = &mt('Existing Roles in this Domain');
2320: } elsif ($showactive) {
2321: $contextrole = &mt('Unexpired Roles in this Domain');
2322: } elsif ($showexpired) {
2323: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2324: }
1.329 raeburn 2325: }
1.393 raeburn 2326: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2327: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2328: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2329: &Apache::loncommon::start_data_table_header_row());
2330: if ($showall) {
2331: $r->print(
2332: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2333: );
2334: } elsif ($showexpired) {
2335: $r->print('<th>'.$lt{'rev'}.'</th>');
2336: }
2337: $r->print(
2338: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2339: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2340: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2341: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2342: if ($output{$type}) {
2343: $r->print($output{$type}."\n");
1.217 raeburn 2344: }
2345: }
1.375 raeburn 2346: $r->print(&Apache::loncommon::end_data_table().
2347: '</fieldset></div>');
1.329 raeburn 2348: }
1.217 raeburn 2349: return;
2350: }
2351:
1.218 raeburn 2352: sub new_coauthor_roles {
2353: my ($r,$ccuname,$ccdomain) = @_;
2354: my $addrolesdisplay = 0;
2355: #
2356: # Co-Author
2357: #
1.406.2.20.2. (raeburn 2358:): my ($cuname,$cudom);
2359:): if (($env{'request.role'} eq "au./$env{'user.domain'}/") ||
2360:): ($env{'request.role'} eq "dc./$env{'user.domain'}/")) {
2361:): $cuname=$env{'user.name'};
2362:): $cudom=$env{'request.role.domain'};
1.218 raeburn 2363: # No sense in assigning co-author role to yourself
1.406.2.20.2. (raeburn 2364:): if ((&Apache::lonuserutils::authorpriv($cuname,$cudom)) &&
2365:): ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2366:): $addrolesdisplay = 1;
2367:): }
2368:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2369:): ($cudom,$cuname) = ($1,$2);
2370:): if ((&Apache::lonuserutils::coauthorpriv($cuname,$cudom)) &&
2371:): ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain) &&
2372:): ($cudom ne $ccdomain || $cuname ne $ccuname)) {
2373:): $addrolesdisplay = 1;
2374:): }
2375:): }
2376:): if ($addrolesdisplay) {
1.218 raeburn 2377: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2378: 'cs' => "Authoring Space",
1.218 raeburn 2379: 'act' => "Activate",
2380: 'rol' => "Role",
2381: 'ext' => "Extent",
2382: 'sta' => "Start",
2383: 'end' => "End",
2384: 'cau' => "Co-Author",
2385: 'caa' => "Assistant Co-Author",
2386: 'ssd' => "Set Start Date",
2387: 'sed' => "Set End Date"
2388: );
2389: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2390: &Apache::loncommon::start_data_table()."\n".
2391: &Apache::loncommon::start_data_table_header_row()."\n".
2392: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2393: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2394: '<th>'.$lt{'end'}.'</th>'."\n".
2395: &Apache::loncommon::end_data_table_header_row()."\n".
2396: &Apache::loncommon::start_data_table_row().'
2397: <td>
1.291 bisitz 2398: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2399: </td>
2400: <td>'.$lt{'cau'}.'</td>
2401: <td>'.$cudom.'_'.$cuname.'</td>
2402: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2403: <a href=
2404: "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>
2405: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2406: <a href=
2407: "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".
2408: &Apache::loncommon::end_data_table_row()."\n".
2409: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2410: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2411: <td>'.$lt{'caa'}.'</td>
2412: <td>'.$cudom.'_'.$cuname.'</td>
2413: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2414: <a href=
2415: "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>
2416: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2417: <a href=
2418: "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".
2419: &Apache::loncommon::end_data_table_row()."\n".
2420: &Apache::loncommon::end_data_table());
2421: } elsif ($env{'request.role'} =~ /^au\./) {
2422: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2423: $env{'request.role.domain'}))) {
2424: $r->print('<span class="LC_error">'.
2425: &mt('You do not have privileges to assign co-author roles.').
2426: '</span>');
2427: } elsif (($env{'user.name'} eq $ccuname) &&
2428: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2429: $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 2430: }
1.406.2.20.2. (raeburn 2431:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2432:): if (!(&Apache::lonuserutils::coauthorpriv($2,$1))) {
2433:): $r->print('<span class="LC_error">'.
2434:): &mt('You do not have privileges to assign co-author roles.').
2435:): '</span>');
2436:): } elsif (($env{'user.name'} eq $ccuname) &&
2437:): ($env{'user.domain'} eq $ccdomain)) {
2438:): $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'));
2439:): } elsif (($cudom eq $ccdomain) && ($cuname eq $ccuname)) {
2440:): $r->print(&mt("Assigning a co-author or assistant co-author role to an Authoring Space's author is not permitted"));
2441:): }
1.218 raeburn 2442: }
2443: return $addrolesdisplay;;
2444: }
2445:
2446: sub new_domain_roles {
1.357 raeburn 2447: my ($r,$ccdomain) = @_;
1.218 raeburn 2448: my $addrolesdisplay = 0;
2449: #
2450: # Domain level
2451: #
2452: my $num_domain_level = 0;
2453: my $domaintext =
2454: '<h4>'.&mt('Domain Level').'</h4>'.
2455: &Apache::loncommon::start_data_table().
2456: &Apache::loncommon::start_data_table_header_row().
2457: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2458: &mt('Extent').'</th>'.
2459: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2460: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2461: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2462: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2463: foreach my $role (@allroles) {
2464: next if ($role eq 'ad');
1.357 raeburn 2465: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2466: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2467: my $plrole=&Apache::lonnet::plaintext($role);
2468: my %lt=&Apache::lonlocal::texthash(
2469: 'ssd' => "Set Start Date",
2470: 'sed' => "Set End Date"
2471: );
2472: $num_domain_level ++;
2473: $domaintext .=
2474: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2475: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2476: <td>'.$plrole.'</td>
2477: <td>'.$thisdomain.'</td>
2478: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2479: <a href=
2480: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2481: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2482: <a href=
2483: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2484: &Apache::loncommon::end_data_table_row();
2485: }
2486: }
2487: }
2488: $domaintext.= &Apache::loncommon::end_data_table();
2489: if ($num_domain_level > 0) {
2490: $r->print($domaintext);
2491: $addrolesdisplay = 1;
2492: }
2493: return $addrolesdisplay;
2494: }
2495:
1.188 raeburn 2496: sub user_authentication {
1.406.2.17 raeburn 2497: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2498: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2499: my $outcome;
1.406.2.6 raeburn 2500: my %lt=&Apache::lonlocal::texthash(
2501: 'err' => "ERROR",
2502: 'uuas' => "This user has an unrecognized authentication scheme",
2503: 'adcs' => "Please alert a domain coordinator of this situation",
2504: 'sldb' => "Please specify login data below",
2505: 'ld' => "Login Data"
2506: );
1.188 raeburn 2507: # Check for a bad authentication type
2508: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2509: # bad authentication scheme
2510: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2511: &initialize_authen_forms($ccdomain,$formname);
2512:
1.190 raeburn 2513: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2514: $outcome = <<ENDBADAUTH;
2515: <script type="text/javascript" language="Javascript">
1.301 bisitz 2516: // <![CDATA[
1.188 raeburn 2517: $loginscript
1.301 bisitz 2518: // ]]>
1.188 raeburn 2519: </script>
2520: <span class="LC_error">$lt{'err'}:
2521: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2522: <h3>$lt{'ld'}</h3>
2523: $choices
2524: ENDBADAUTH
2525: } else {
2526: # This user is not allowed to modify the user's
2527: # authentication scheme, so just notify them of the problem
2528: $outcome = <<ENDBADAUTH;
2529: <span class="LC_error"> $lt{'err'}:
2530: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2531: </span>
2532: ENDBADAUTH
2533: }
2534: } else { # Authentication type is valid
1.227 raeburn 2535: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2536: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2537: &modify_login_block($ccdomain,$currentauth);
2538: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2539: # Current user has login modification privileges
2540: $outcome =
2541: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2542: '// <![CDATA['."\n".
1.188 raeburn 2543: $loginscript."\n".
1.301 bisitz 2544: '// ]]>'."\n".
1.188 raeburn 2545: '</script>'."\n".
2546: '<h3>'.$lt{'ld'}.'</h3>'.
2547: &Apache::loncommon::start_data_table().
1.205 raeburn 2548: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2549: '<td>'.$authformnop;
1.406.2.6 raeburn 2550: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2551: $outcome .= '</td>'."\n".
2552: &Apache::loncommon::end_data_table_row().
2553: &Apache::loncommon::start_data_table_row().
2554: '<td>'.$authformcurrent.'</td>'.
2555: &Apache::loncommon::end_data_table_row()."\n";
2556: } else {
1.200 raeburn 2557: $outcome .= ' ('.$authformcurrent.')</td>'.
2558: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2559: }
1.406.2.6 raeburn 2560: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2561: foreach my $item (@authform_others) {
2562: $outcome .= &Apache::loncommon::start_data_table_row().
2563: '<td>'.$item.'</td>'.
2564: &Apache::loncommon::end_data_table_row()."\n";
2565: }
1.188 raeburn 2566: }
1.205 raeburn 2567: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2568: } else {
1.406.2.17 raeburn 2569: if (($currentauth =~ /^internal:/) &&
2570: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2571: $outcome = <<"ENDJS";
2572: <script type="text/javascript">
2573: // <![CDATA[
2574: function togglePwd(form) {
2575: if (form.newintpwd.length) {
2576: if (document.getElementById('LC_ownersetpwd')) {
2577: for (var i=0; i<form.newintpwd.length; i++) {
2578: if (form.newintpwd[i].checked) {
2579: if (form.newintpwd[i].value == 1) {
2580: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2581: } else {
2582: document.getElementById('LC_ownersetpwd').style.display = 'none';
2583: }
2584: }
2585: }
2586: }
2587: }
2588: }
2589: // ]]>
2590: </script>
2591: ENDJS
2592:
2593: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2594: &Apache::loncommon::start_data_table().
2595: &Apache::loncommon::start_data_table_row().
2596: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2597: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2598: &mt('No').'</label>'.(' 'x2).
2599: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2600: '<div id="LC_ownersetpwd" style="display:none">'.
2601: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2602: '<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>'.
2603: &Apache::loncommon::end_data_table_row().
2604: &Apache::loncommon::end_data_table();
2605: }
1.406.2.6 raeburn 2606: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2607: # Current user has rights to view domain preferences for user's domain
2608: my $result;
2609: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2610: my ($krbver,$krbrealm) = ($1,$2);
2611: if ($krbrealm eq '') {
2612: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2613: } else {
2614: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2615: $krbrealm,$krbver);
1.406.2.6 raeburn 2616: }
2617: } elsif ($currentauth =~ /^internal:/) {
2618: $result = &mt('Currently internally authenticated.');
2619: } elsif ($currentauth =~ /^localauth:/) {
2620: $result = &mt('Currently using local (institutional) authentication.');
2621: } elsif ($currentauth =~ /^unix:/) {
2622: $result = &mt('Currently Filesystem Authenticated.');
2623: }
2624: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2625: &Apache::loncommon::start_data_table().
2626: &Apache::loncommon::start_data_table_row().
2627: '<td>'.$result.'</td>'.
2628: &Apache::loncommon::end_data_table_row()."\n".
2629: &Apache::loncommon::end_data_table();
2630: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2631: my %lt=&Apache::lonlocal::texthash(
2632: 'ccld' => "Change Current Login Data",
2633: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2634: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2635: );
2636: $outcome .= <<ENDNOPRIV;
2637: <h3>$lt{'ccld'}</h3>
2638: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2639: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2640: ENDNOPRIV
2641: }
2642: }
2643: } ## End of "check for bad authentication type" logic
2644: return $outcome;
2645: }
2646:
1.187 raeburn 2647: sub modify_login_block {
2648: my ($dom,$currentauth) = @_;
2649: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2650: my ($authnum,%can_assign) =
2651: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2652: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2653: if ($currentauth=~/^krb(4|5):/) {
2654: $authformcurrent=$authformkrb;
2655: if ($can_assign{'int'}) {
1.205 raeburn 2656: push(@authform_others,$authformint);
1.187 raeburn 2657: }
2658: if ($can_assign{'loc'}) {
1.205 raeburn 2659: push(@authform_others,$authformloc);
1.187 raeburn 2660: }
2661: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2662: $show_override_msg = 1;
2663: }
2664: } elsif ($currentauth=~/^internal:/) {
2665: $authformcurrent=$authformint;
2666: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2667: push(@authform_others,$authformkrb);
1.187 raeburn 2668: }
2669: if ($can_assign{'loc'}) {
1.205 raeburn 2670: push(@authform_others,$authformloc);
1.187 raeburn 2671: }
2672: if ($can_assign{'int'}) {
2673: $show_override_msg = 1;
2674: }
2675: } elsif ($currentauth=~/^unix:/) {
2676: $authformcurrent=$authformfsys;
2677: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2678: push(@authform_others,$authformkrb);
1.187 raeburn 2679: }
2680: if ($can_assign{'int'}) {
1.205 raeburn 2681: push(@authform_others,$authformint);
1.187 raeburn 2682: }
2683: if ($can_assign{'loc'}) {
1.205 raeburn 2684: push(@authform_others,$authformloc);
1.187 raeburn 2685: }
2686: if ($can_assign{'fsys'}) {
2687: $show_override_msg = 1;
2688: }
2689: } elsif ($currentauth=~/^localauth:/) {
2690: $authformcurrent=$authformloc;
2691: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2692: push(@authform_others,$authformkrb);
1.187 raeburn 2693: }
2694: if ($can_assign{'int'}) {
1.205 raeburn 2695: push(@authform_others,$authformint);
1.187 raeburn 2696: }
2697: if ($can_assign{'loc'}) {
2698: $show_override_msg = 1;
2699: }
2700: }
2701: if ($show_override_msg) {
1.205 raeburn 2702: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2703: '</td></tr>'."\n".
2704: '<tr><td> </td>'.
2705: '<td><b>'.&mt('Currently in use').'</b></td>'.
2706: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2707: &mt('will override current values').
1.205 raeburn 2708: '</span></td></tr></table>';
1.187 raeburn 2709: }
1.205 raeburn 2710: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2711: }
2712:
1.188 raeburn 2713: sub personal_data_display {
1.406.2.20.2. (raeburn 2714:): my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$readonly,$rolesarray,$now,
1.406.2.20 raeburn 2715: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.406.2.20.2. (raeburn 2716:): my ($output,%userenv,%canmodify,%canmodify_status,$disabled);
1.219 raeburn 2717: my @userinfo = ('firstname','middlename','lastname','generation',
2718: 'permanentemail','id');
1.252 raeburn 2719: my $rowcount = 0;
2720: my $editable = 0;
1.391 raeburn 2721: my %textboxsize = (
2722: firstname => '15',
2723: middlename => '15',
2724: lastname => '15',
2725: generation => '5',
2726: permanentemail => '25',
2727: id => '15',
2728: );
2729:
2730: my %lt=&Apache::lonlocal::texthash(
2731: 'pd' => "Personal Data",
2732: 'firstname' => "First Name",
2733: 'middlename' => "Middle Name",
2734: 'lastname' => "Last Name",
2735: 'generation' => "Generation",
2736: 'permanentemail' => "Permanent e-mail address",
2737: 'id' => "Student/Employee ID",
2738: 'lg' => "Login Data",
2739: 'inststatus' => "Affiliation",
2740: 'email' => 'E-mail address',
2741: 'valid' => 'Validation',
1.406.2.16 raeburn 2742: 'username' => 'Username',
1.391 raeburn 2743: );
2744:
2745: %canmodify_status =
1.286 raeburn 2746: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2747: ['inststatus'],$rolesarray);
1.253 raeburn 2748: if (!$newuser) {
1.188 raeburn 2749: # Get the users information
2750: %userenv = &Apache::lonnet::get('environment',
2751: ['firstname','middlename','lastname','generation',
1.286 raeburn 2752: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2753: %canmodify =
2754: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2755: \@userinfo,$rolesarray);
1.257 raeburn 2756: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2757: if ($newuser eq 'email') {
1.396 raeburn 2758: if (ref($emailusername) eq 'HASH') {
2759: if (ref($emailusername->{$usertype}) eq 'HASH') {
2760: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16 raeburn 2761: @userinfo = ();
1.396 raeburn 2762: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2763: foreach my $field (@{$infofields}) {
2764: if ($emailusername->{$usertype}->{$field}) {
2765: push(@userinfo,$field);
2766: $canmodify{$field} = 1;
2767: unless ($textboxsize{$field}) {
2768: $textboxsize{$field} = 25;
2769: }
2770: unless ($lt{$field}) {
2771: $lt{$field} = $infotitles->{$field};
2772: }
2773: if ($emailusername->{$usertype}->{$field} eq 'required') {
2774: $lt{$field} .= '<b>*</b>';
2775: }
1.391 raeburn 2776: }
2777: }
2778: }
2779: }
2780: }
2781: } else {
2782: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2783: $inst_results,$rolesarray);
2784: }
1.406.2.20.2. (raeburn 2785:): } elsif ($readonly) {
2786:): $disabled = ' disabled="disabled"';
1.188 raeburn 2787: }
1.391 raeburn 2788:
1.188 raeburn 2789: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2790: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2791: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2792: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16 raeburn 2793: my $size = 25;
2794: if ($condition) {
2795: if ($condition =~ /^\@[^\@]+$/) {
2796: $size = 10;
2797: } else {
2798: undef($condition);
2799: }
2800: }
2801: if ($excluded) {
2802: unless ($excluded =~ /^\@[^\@]+$/) {
2803: undef($condition);
2804: }
2805: }
1.396 raeburn 2806: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2807: 'LC_oddrow_value')."\n".
1.406.2.16 raeburn 2808: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2809: if ($condition) {
2810: $output .= $condition;
2811: } elsif ($excluded) {
2812: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2813: $excluded).'</span>';
2814: }
2815: if ($usernameset eq 'first') {
2816: $output .= '<br /><span style="font-size: smaller">';
2817: if ($condition) {
2818: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2819: $condition);
2820: } else {
2821: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2822: }
2823: $output .= '</span>';
2824: }
1.391 raeburn 2825: $rowcount ++;
2826: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.20.2. (raeburn 2827:): my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2828:): my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2829: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2830: 'LC_pick_box_title',
2831: 'LC_oddrow_value')."\n".
2832: $upassone."\n".
2833: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2834: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2835: 'LC_pick_box_title',
2836: 'LC_oddrow_value')."\n".
2837: $upasstwo.
2838: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16 raeburn 2839: if ($usernameset eq 'free') {
2840: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2841: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.406.2.20 raeburn 2842: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2843: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2844: &mt('Yes').'</label>'.(' 'x2).
2845: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2846: &mt('No').'</label></span>'."\n".
1.406.2.16 raeburn 2847: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2848: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2849: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2850: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2851: $rowcount ++;
2852: }
1.391 raeburn 2853: }
1.188 raeburn 2854: foreach my $item (@userinfo) {
2855: my $rowtitle = $lt{$item};
1.252 raeburn 2856: my $hiderow = 0;
1.188 raeburn 2857: if ($item eq 'generation') {
2858: $rowtitle = $genhelp.$rowtitle;
2859: }
1.252 raeburn 2860: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2861: if ($newuser) {
1.210 raeburn 2862: if (ref($inst_results) eq 'HASH') {
2863: if ($inst_results->{$item} ne '') {
1.252 raeburn 2864: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2865: } else {
1.252 raeburn 2866: if ($context eq 'selfcreate') {
1.391 raeburn 2867: if ($canmodify{$item}) {
1.394 raeburn 2868: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2869: $editable ++;
2870: } else {
2871: $hiderow = 1;
2872: }
1.253 raeburn 2873: } else {
1.406.2.20.2. (raeburn 2874:): $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2875: }
1.210 raeburn 2876: }
1.188 raeburn 2877: } else {
1.252 raeburn 2878: if ($context eq 'selfcreate') {
1.401 raeburn 2879: if ($canmodify{$item}) {
2880: if ($newuser eq 'email') {
2881: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2882: } else {
1.401 raeburn 2883: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2884: }
1.401 raeburn 2885: $editable ++;
2886: } else {
2887: $hiderow = 1;
1.252 raeburn 2888: }
1.253 raeburn 2889: } else {
1.406.2.20.2. (raeburn 2890:): $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2891: }
1.188 raeburn 2892: }
2893: } else {
1.219 raeburn 2894: if ($canmodify{$item}) {
1.252 raeburn 2895: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2896: if (($item eq 'id') && (!$newuser)) {
2897: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2898: }
1.188 raeburn 2899: } else {
1.252 raeburn 2900: $row .= $userenv{$item};
1.188 raeburn 2901: }
2902: }
1.252 raeburn 2903: $row .= &Apache::lonhtmlcommon::row_closure(1);
2904: if (!$hiderow) {
2905: $output .= $row;
2906: $rowcount ++;
2907: }
1.188 raeburn 2908: }
1.286 raeburn 2909: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2910: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2911: if (ref($types) eq 'ARRAY') {
2912: if (@{$types} > 0) {
2913: my ($hiderow,$shown);
2914: if ($canmodify_status{'inststatus'}) {
2915: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2916: } else {
2917: if ($userenv{'inststatus'} eq '') {
2918: $hiderow = 1;
1.334 raeburn 2919: } else {
2920: my @showitems;
2921: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2922: if (exists($usertypes->{$item})) {
2923: push(@showitems,$usertypes->{$item});
2924: } else {
2925: push(@showitems,$item);
2926: }
2927: }
2928: if (@showitems) {
2929: $shown = join(', ',@showitems);
2930: } else {
2931: $hiderow = 1;
2932: }
1.286 raeburn 2933: }
2934: }
2935: if (!$hiderow) {
1.389 bisitz 2936: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2937: $shown.&Apache::lonhtmlcommon::row_closure(1);
2938: if ($context eq 'selfcreate') {
2939: $rowcount ++;
2940: }
2941: $output .= $row;
2942: }
2943: }
2944: }
2945: }
1.391 raeburn 2946: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2947: if ($captchaform) {
1.406.2.2 raeburn 2948: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2949: 'LC_pick_box_title')."\n".
2950: $captchaform."\n".'<br /><br />'.
2951: &Apache::lonhtmlcommon::row_closure(1);
2952: $rowcount ++;
2953: }
1.406.2.20 raeburn 2954: if ($showsubmit) {
2955: my $submit_text = &mt('Create account');
2956: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2957: '<br /><input type="submit" name="createaccount" value="'.
2958: $submit_text.'" />';
2959: if ($usertype ne '') {
1.406.2.20.2. (raeburn 2960:): $output .= '<input type="hidden" name="type" value="'.
2961:): &HTML::Entities::encode($usertype,'\'<>"&').'" />';
1.406.2.20 raeburn 2962: }
1.406.2.20.2. (raeburn 2963:): $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.20 raeburn 2964: }
1.391 raeburn 2965: }
1.188 raeburn 2966: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2967: if (wantarray) {
1.252 raeburn 2968: if ($context eq 'selfcreate') {
2969: return($output,$rowcount,$editable);
2970: } else {
1.388 bisitz 2971: return $output;
1.252 raeburn 2972: }
1.206 raeburn 2973: } else {
2974: return $output;
2975: }
1.188 raeburn 2976: }
2977:
1.286 raeburn 2978: sub pick_inst_statuses {
2979: my ($curr,$usertypes,$types) = @_;
2980: my ($output,$rem,@currtypes);
2981: if ($curr ne '') {
2982: @currtypes = map { &unescape($_); } split(/:/,$curr);
2983: }
2984: my $numinrow = 2;
2985: if (ref($types) eq 'ARRAY') {
2986: $output = '<table>';
2987: my $lastcolspan;
2988: for (my $i=0; $i<@{$types}; $i++) {
2989: if (defined($usertypes->{$types->[$i]})) {
2990: my $rem = $i%($numinrow);
2991: if ($rem == 0) {
2992: if ($i<@{$types}-1) {
2993: if ($i > 0) {
2994: $output .= '</tr>';
2995: }
2996: $output .= '<tr>';
2997: }
2998: } elsif ($i==@{$types}-1) {
2999: my $colsleft = $numinrow - $rem;
3000: if ($colsleft > 1) {
3001: $lastcolspan = ' colspan="'.$colsleft.'"';
3002: }
3003: }
3004: my $check = ' ';
3005: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
3006: $check = ' checked="checked" ';
3007: }
3008: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
3009: '<span class="LC_nobreak"><label>'.
3010: '<input type="checkbox" name="inststatus" '.
3011: 'value="'.$types->[$i].'"'.$check.'/>'.
3012: $usertypes->{$types->[$i]}.'</label></span></td>';
3013: }
3014: }
3015: $output .= '</tr></table>';
3016: }
3017: return $output;
3018: }
3019:
1.257 raeburn 3020: sub selfcreate_canmodify {
3021: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
3022: if (ref($inst_results) eq 'HASH') {
3023: my @inststatuses = &get_inststatuses($inst_results);
3024: if (@inststatuses == 0) {
3025: @inststatuses = ('default');
3026: }
3027: $rolesarray = \@inststatuses;
3028: }
3029: my %canmodify =
3030: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
3031: $rolesarray);
3032: return %canmodify;
3033: }
3034:
1.252 raeburn 3035: sub get_inststatuses {
3036: my ($insthashref) = @_;
3037: my @inststatuses = ();
3038: if (ref($insthashref) eq 'HASH') {
3039: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
3040: @inststatuses = @{$insthashref->{'inststatus'}};
3041: }
3042: }
3043: return @inststatuses;
3044: }
3045:
1.4 www 3046: # ================================================================= Phase Three
1.42 matthew 3047: sub update_user_data {
1.406.2.17 raeburn 3048: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 3049: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
3050: $env{'form.ccdomain'});
1.27 matthew 3051: # Error messages
1.188 raeburn 3052: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 3053: my $end = '</span><br /><br />';
3054: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 3055: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 3056: &mt('Return to previous page').'</a>'.
3057: &Apache::loncommon::end_page();
3058: my $now = time;
1.40 www 3059: my $title;
1.101 albertel 3060: if (exists($env{'form.makeuser'})) {
1.40 www 3061: $title='Set Privileges for New User';
3062: } else {
3063: $title='Modify User Privileges';
3064: }
1.213 raeburn 3065: my $newuser = 0;
1.160 raeburn 3066: my ($jsback,$elements) = &crumb_utilities();
3067: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 3068: '// <![CDATA['."\n".
3069: $jsback."\n".
3070: '// ]]>'."\n".
3071: '</script>'."\n";
1.406.2.7 raeburn 3072: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 3073: push (@{$brcrum},
3074: {href => "javascript:backPage(document.userupdate)",
3075: text => $breadcrumb_text{'search'},
3076: faq => 282,
3077: bug => 'Instructor Interface',}
3078: );
3079: if ($env{'form.prevphase'} eq 'userpicked') {
3080: push(@{$brcrum},
3081: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
3082: text => $breadcrumb_text{'userpicked'},
3083: faq => 282,
3084: bug => 'Instructor Interface',});
1.233 raeburn 3085: }
1.224 raeburn 3086: my $helpitem = 'Course_Change_Privileges';
3087: if ($env{'form.action'} eq 'singlestudent') {
3088: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 3089: } elsif ($context eq 'author') {
3090: $helpitem = 'Author_Change_Privileges';
3091: } elsif ($context eq 'domain') {
3092: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 3093: }
1.351 raeburn 3094: push(@{$brcrum},
3095: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
3096: text => $breadcrumb_text{'modify'},
3097: faq => 282,
3098: bug => 'Instructor Interface',},
3099: {href => "/adm/createuser",
3100: text => "Result",
3101: faq => 282,
3102: bug => 'Instructor Interface',
3103: help => $helpitem});
3104: my $args = {bread_crumbs => $brcrum,
3105: bread_crumbs_component => 'User Management'};
3106: if ($env{'form.popup'}) {
3107: $args->{'no_nav_bar'} = 1;
3108: }
3109: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 3110: $r->print(&update_result_form($uhome));
1.27 matthew 3111: # Check Inputs
1.101 albertel 3112: if (! $env{'form.ccuname'} ) {
1.193 raeburn 3113: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 3114: return;
3115: }
1.138 albertel 3116: if ( $env{'form.ccuname'} ne
3117: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 3118: $r->print($error.&mt('Invalid login name.').' '.
3119: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 3120: $end.$rtnlink);
1.27 matthew 3121: return;
3122: }
1.101 albertel 3123: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 3124: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 3125: return;
3126: }
1.138 albertel 3127: if ( $env{'form.ccdomain'} ne
3128: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 3129: $r->print($error.&mt('Invalid domain name.').' '.
3130: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 3131: $end.$rtnlink);
1.27 matthew 3132: return;
3133: }
1.219 raeburn 3134: if ($uhome eq 'no_host') {
3135: $newuser = 1;
3136: }
1.101 albertel 3137: if (! exists($env{'form.makeuser'})) {
1.29 matthew 3138: # Modifying an existing user, so check the validity of the name
3139: if ($uhome eq 'no_host') {
1.389 bisitz 3140: $r->print(
3141: $error
3142: .'<p class="LC_error">'
3143: .&mt('Unable to determine home server for [_1] in domain [_2].',
3144: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
3145: .'</p>');
1.29 matthew 3146: return;
3147: }
3148: }
1.27 matthew 3149: # Determine authentication method and password for the user being modified
3150: my $amode='';
3151: my $genpwd='';
1.101 albertel 3152: if ($env{'form.login'} eq 'krb') {
1.41 albertel 3153: $amode='krb';
1.101 albertel 3154: $amode.=$env{'form.krbver'};
3155: $genpwd=$env{'form.krbarg'};
3156: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 3157: $amode='internal';
1.101 albertel 3158: $genpwd=$env{'form.intarg'};
3159: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 3160: $amode='unix';
1.101 albertel 3161: $genpwd=$env{'form.fsysarg'};
3162: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 3163: $amode='localauth';
1.101 albertel 3164: $genpwd=$env{'form.locarg'};
1.27 matthew 3165: $genpwd=" " if (!$genpwd);
1.101 albertel 3166: } elsif (($env{'form.login'} eq 'nochange') ||
3167: ($env{'form.login'} eq '' )) {
1.34 matthew 3168: # There is no need to tell the user we did not change what they
3169: # did not ask us to change.
1.35 matthew 3170: # If they are creating a new user but have not specified login
3171: # information this will be caught below.
1.30 matthew 3172: } else {
1.367 golterma 3173: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
3174: return;
1.27 matthew 3175: }
1.164 albertel 3176:
1.188 raeburn 3177: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 3178: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
3179: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
3180: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 3181:
1.193 raeburn 3182: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 3183: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.406.2.20.2. (raeburn 3184:): my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.384 raeburn 3185: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 3186: my @requestauthor = ('requestauthor');
1.406.2.20.2. (raeburn 3187:): my @authordefaults = ('webdav','editors','archive');
1.286 raeburn 3188: my ($othertitle,$usertypes,$types) =
3189: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 3190: my %canmodify_status =
3191: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
3192: ['inststatus']);
1.101 albertel 3193: if ($env{'form.makeuser'}) {
1.164 albertel 3194: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 3195: # Check for the authentication mode and password
3196: if (! $amode || ! $genpwd) {
1.193 raeburn 3197: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 3198: return;
1.18 albertel 3199: }
1.29 matthew 3200: # Determine desired host
1.101 albertel 3201: my $desiredhost = $env{'form.hserver'};
1.29 matthew 3202: if (lc($desiredhost) eq 'default') {
3203: $desiredhost = undef;
3204: } else {
1.147 albertel 3205: my %home_servers =
3206: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 3207: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 3208: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
3209: return;
3210: }
3211: }
3212: # Check ID format
3213: my %checkhash;
3214: my %checks = ('id' => 1);
3215: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 3216: 'newuser' => $newuser,
1.196 raeburn 3217: 'id' => $env{'form.cid'},
1.193 raeburn 3218: );
1.196 raeburn 3219: if ($env{'form.cid'} ne '') {
3220: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
3221: \%rulematch,\%inst_results,\%curr_rules);
3222: if (ref($alerts{'id'}) eq 'HASH') {
3223: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3224: my $domdesc =
3225: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
3226: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
3227: my $userchkmsg;
3228: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
3229: $userchkmsg =
3230: &Apache::loncommon::instrule_disallow_msg('id',
3231: $domdesc,1).
3232: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
3233: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
3234: }
3235: $r->print($error.&mt('Invalid ID format').$end.
3236: $userchkmsg.$rtnlink);
3237: return;
3238: }
3239: }
1.29 matthew 3240: }
3241: }
1.367 golterma 3242: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 3243: # Call modifyuser
3244: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 3245: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 3246: $amode,$genpwd,$env{'form.cfirstname'},
3247: $env{'form.cmiddlename'},$env{'form.clastname'},
3248: $env{'form.cgeneration'},undef,$desiredhost,
3249: $env{'form.cpermanentemail'});
1.77 www 3250: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 3251: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 3252: $env{'form.ccdomain'});
1.334 raeburn 3253: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 3254: if ($uhome ne 'no_host') {
1.334 raeburn 3255: if ($context eq 'domain') {
1.378 raeburn 3256: foreach my $name ('portfolio','author') {
3257: if ($env{'form.custom_'.$name.'quota'} == 1) {
3258: if ($env{'form.'.$name.'quota'} eq '') {
3259: $newcustom{$name.'quota'} = 0;
3260: } else {
3261: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
3262: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
3263: }
3264: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
3265: $changed{$name.'quota'} = 1;
3266: }
1.334 raeburn 3267: }
3268: }
3269: foreach my $item (@usertools) {
3270: if ($env{'form.custom'.$item} == 1) {
3271: $newcustom{$item} = $env{'form.tools_'.$item};
3272: $changed{$item} = &tool_admin($item,$newcustom{$item},
3273: \%changeHash,'tools');
3274: }
1.267 raeburn 3275: }
1.334 raeburn 3276: foreach my $item (@requestcourses) {
1.341 raeburn 3277: if ($env{'form.custom'.$item} == 1) {
3278: $newcustom{$item} = $env{'form.crsreq_'.$item};
3279: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3280: $newcustom{$item} .= '=';
1.383 raeburn 3281: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3282: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3283: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3284: }
1.334 raeburn 3285: }
1.341 raeburn 3286: $changed{$item} = &tool_admin($item,$newcustom{$item},
3287: \%changeHash,'requestcourses');
1.334 raeburn 3288: }
1.275 raeburn 3289: }
1.362 raeburn 3290: if ($env{'form.customrequestauthor'} == 1) {
3291: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3292: $changed{'requestauthor'} = &tool_admin('requestauthor',
3293: $newcustom{'requestauthor'},
3294: \%changeHash,'requestauthor');
3295: }
1.406.2.20.2. (raeburn 3296:): if ($env{'form.customeditors'} == 1) {
3297:): my @editors;
3298:): my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
3299:): if (@posseditors) {
3300:): foreach my $editor (@posseditors) {
3301:): if (grep(/^\Q$editor\E$/,@posseditors)) {
3302:): unless (grep(/^\Q$editor\E$/,@editors)) {
3303:): push(@editors,$editor);
3304:): }
3305:): }
3306:): }
3307:): }
3308:): if (@editors) {
3309:): @editors = sort(@editors);
3310:): $changed{'editors'} = &tool_admin('editors',join(',',@editors),
3311:): \%changeHash,'authordefaults');
3312:): }
3313:): }
3314:): if ($env{'form.customwebdav'} == 1) {
3315:): $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
3316:): $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
3317:): \%changeHash,'authordefaults');
3318:): }
3319:): if ($env{'form.customarchive'} == 1) {
3320:): $newcustom{'archive'} = $env{'form.authordefaults_archive'};
3321:): $changed{'archive'} = &tool_admin('archive',$newcustom{'archive'},
3322:): \%changeHash,'authordefaults');
3323:):
3324:): }
1.275 raeburn 3325: }
1.334 raeburn 3326: if ($canmodify_status{'inststatus'}) {
3327: if (exists($env{'form.inststatus'})) {
3328: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3329: if (@inststatuses > 0) {
3330: $changeHash{'inststatus'} = join(',',@inststatuses);
3331: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3332: }
3333: }
1.232 raeburn 3334: }
1.334 raeburn 3335: if (keys(%changed)) {
3336: foreach my $item (@userinfo) {
3337: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3338: }
1.267 raeburn 3339: my $chgresult =
3340: &Apache::lonnet::put('environment',\%changeHash,
3341: $env{'form.ccdomain'},$env{'form.ccuname'});
3342: }
1.232 raeburn 3343: }
1.406.2.19 raeburn 3344: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3345: &Apache::lonnet::hostname($uhome));
1.101 albertel 3346: } elsif (($env{'form.login'} ne 'nochange') &&
3347: ($env{'form.login'} ne '' )) {
1.27 matthew 3348: # Modify user privileges
3349: if (! $amode || ! $genpwd) {
1.193 raeburn 3350: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3351: return;
1.20 harris41 3352: }
1.395 bisitz 3353: # Only allow authentication modification if the person has authority
1.101 albertel 3354: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3355: $r->print('Modifying authentication: '.
1.31 matthew 3356: &Apache::lonnet::modifyuserauth(
1.101 albertel 3357: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3358: $amode,$genpwd));
1.406.2.19 raeburn 3359: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3360: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3361: } else {
1.27 matthew 3362: # Okay, this is a non-fatal error.
1.406.2.17 raeburn 3363: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3364: }
1.406.2.17 raeburn 3365: } elsif (($env{'form.intarg'} ne '') &&
3366: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3367: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3368: $r->print('Modifying authentication: '.
3369: &Apache::lonnet::modifyuserauth(
3370: $env{'form.ccdomain'},$env{'form.ccuname'},
3371: 'internal',$env{'form.intarg'}));
1.28 matthew 3372: }
1.344 bisitz 3373: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3374: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3375: ##
1.375 raeburn 3376: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3377: if ($context eq 'course') {
1.375 raeburn 3378: ($cnum,$cdom) =
3379: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3380: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3381: if ($showcredits) {
3382: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3383: }
1.213 raeburn 3384: }
1.101 albertel 3385: if (! $env{'form.makeuser'} ) {
1.28 matthew 3386: # Check for need to change
3387: my %userenv = &Apache::lonnet::get
1.134 raeburn 3388: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3389: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.406.2.20.2. (raeburn 3390:): 'tools.aboutme','tools.blog','tools.webdav',
3391:): 'tools.portfolio','tools.timezone','tools.portaccess',
3392:): 'authormanagers','authoreditors','authorarchive','requestauthor',
1.361 raeburn 3393: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3394: 'requestcourses.community','requestcourses.textbook',
3395: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.406.2.20.2. (raeburn 3396:): 'reqcrsotherdom.community','reqcrsotherdom.textbook',
3397:): 'domcoord.author'],
1.160 raeburn 3398: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3399: my ($tmp) = keys(%userenv);
3400: if ($tmp =~ /^(con_lost|error)/i) {
3401: %userenv = ();
3402: }
1.406.2.20.2. (raeburn 3403:): unless (($userenv{'domcoord.author'} eq 'blocked') &&
3404:): (($env{'user.name'} ne $env{'form.ccuname'}) ||
3405:): ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
3406:): push(@authordefaults,'managers');
3407:): }
1.206 raeburn 3408: my $no_forceid_alert;
3409: # Check to see if user information can be changed
3410: my %domconfig =
3411: &Apache::lonnet::get_dom('configuration',['usermodification'],
3412: $env{'form.ccdomain'});
1.213 raeburn 3413: my @statuses = ('active','future');
3414: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3415: my ($auname,$audom);
1.220 raeburn 3416: if ($context eq 'author') {
1.206 raeburn 3417: $auname = $env{'user.name'};
3418: $audom = $env{'user.domain'};
3419: }
3420: foreach my $item (keys(%roles)) {
1.220 raeburn 3421: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3422: if ($context eq 'course') {
3423: if ($cnum ne '' && $cdom ne '') {
3424: if ($rolenum eq $cnum && $roledom eq $cdom) {
3425: if (!grep(/^\Q$role\E$/,@userroles)) {
3426: push(@userroles,$role);
3427: }
3428: }
3429: }
3430: } elsif ($context eq 'author') {
3431: if ($rolenum eq $auname && $roledom eq $audom) {
3432: if (!grep(/^\Q$role\E$/,@userroles)) {
3433: push(@userroles,$role);
3434: }
3435: }
3436: }
3437: }
1.220 raeburn 3438: if ($env{'form.action'} eq 'singlestudent') {
3439: if (!grep(/^st$/,@userroles)) {
3440: push(@userroles,'st');
3441: }
3442: } else {
3443: # Check for course or co-author roles being activated or re-enabled
3444: if ($context eq 'author' || $context eq 'course') {
3445: foreach my $key (keys(%env)) {
3446: if ($context eq 'author') {
3447: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3448: if (!grep(/^\Q$1\E$/,@userroles)) {
3449: push(@userroles,$1);
3450: }
3451: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3452: if (!grep(/^\Q$1\E$/,@userroles)) {
3453: push(@userroles,$1);
3454: }
1.206 raeburn 3455: }
1.220 raeburn 3456: } elsif ($context eq 'course') {
3457: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3458: if (!grep(/^\Q$1\E$/,@userroles)) {
3459: push(@userroles,$1);
3460: }
3461: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3462: if (!grep(/^\Q$1\E$/,@userroles)) {
3463: push(@userroles,$1);
3464: }
1.206 raeburn 3465: }
3466: }
3467: }
3468: }
3469: }
3470: #Check to see if we can change personal data for the user
3471: my (@mod_disallowed,@longroles);
3472: foreach my $role (@userroles) {
3473: if ($role eq 'cr') {
3474: push(@longroles,'Custom');
3475: } else {
1.318 raeburn 3476: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3477: }
3478: }
1.219 raeburn 3479: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3480: foreach my $item (@userinfo) {
1.28 matthew 3481: # Strip leading and trailing whitespace
1.203 raeburn 3482: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3483: if (!$canmodify{$item}) {
1.207 raeburn 3484: if (defined($env{'form.c'.$item})) {
3485: if ($env{'form.c'.$item} ne $userenv{$item}) {
3486: push(@mod_disallowed,$item);
3487: }
1.206 raeburn 3488: }
3489: $env{'form.c'.$item} = $userenv{$item};
3490: }
1.28 matthew 3491: }
1.259 bisitz 3492: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3493: my $forceid = $env{'form.forceid'};
3494: my $recurseid = $env{'form.recurseid'};
3495: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3496: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3497: $env{'form.ccuname'});
3498: if (($uidhash{$env{'form.ccuname'}}) &&
3499: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3500: (!$forceid)) {
3501: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3502: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3503: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3504: .'<br />'
3505: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3506: .'<br />'."\n";
1.203 raeburn 3507: }
3508: }
3509: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3510: my $checkhash;
3511: my $checks = { 'id' => 1 };
3512: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3513: { 'newuser' => $newuser,
3514: 'id' => $env{'form.cid'},
3515: };
3516: &Apache::loncommon::user_rule_check($checkhash,$checks,
3517: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3518: if (ref($alerts{'id'}) eq 'HASH') {
3519: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3520: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3521: }
3522: }
3523: }
1.378 raeburn 3524: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3525: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3526: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3527: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3528: @disporder = ('inststatus');
3529: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.406.2.20.2. (raeburn 3530:): push(@disporder,('requestcourses','requestauthor','authordefaults'));
1.334 raeburn 3531: } else {
3532: push(@disporder,'reqcrsotherdom');
3533: }
3534: push(@disporder,('quota','tools'));
1.338 raeburn 3535: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3536: foreach my $name ('portfolio','author') {
3537: ($olddefquota{$name},$oldsettingstatus{$name}) =
3538: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3539: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3540: }
1.334 raeburn 3541: my %canshow;
1.220 raeburn 3542: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3543: $canshow{'quota'} = 1;
1.220 raeburn 3544: }
1.267 raeburn 3545: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3546: $canshow{'tools'} = 1;
1.267 raeburn 3547: }
1.275 raeburn 3548: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3549: $canshow{'requestcourses'} = 1;
1.300 raeburn 3550: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3551: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3552: }
1.286 raeburn 3553: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3554: $canshow{'inststatus'} = 1;
1.286 raeburn 3555: }
1.362 raeburn 3556: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3557: $canshow{'requestauthor'} = 1;
1.406.2.20.2. (raeburn 3558:): $canshow{'authordefaults'} = 1;
1.362 raeburn 3559: }
1.267 raeburn 3560: my (%changeHash,%changed);
1.286 raeburn 3561: if ($oldinststatus eq '') {
1.334 raeburn 3562: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3563: } else {
3564: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3565: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3566: } else {
1.334 raeburn 3567: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3568: }
3569: }
3570: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3571: if ($canmodify_status{'inststatus'}) {
3572: $canshow{'inststatus'} = 1;
1.286 raeburn 3573: if (exists($env{'form.inststatus'})) {
3574: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3575: if (@inststatuses > 0) {
3576: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3577: $changeHash{'inststatus'} = $newinststatus;
3578: if ($newinststatus ne $oldinststatus) {
3579: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3580: foreach my $name ('portfolio','author') {
3581: ($newdefquota{$name},$newsettingstatus{$name}) =
3582: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3583: }
1.286 raeburn 3584: }
3585: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3586: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3587: } else {
1.337 raeburn 3588: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3589: }
1.334 raeburn 3590: }
3591: } else {
3592: $newinststatus = '';
3593: $changeHash{'inststatus'} = $newinststatus;
3594: $newsettings{'inststatus'} = $othertitle;
3595: if ($newinststatus ne $oldinststatus) {
3596: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3597: foreach my $name ('portfolio','author') {
3598: ($newdefquota{$name},$newsettingstatus{$name}) =
3599: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3600: }
1.286 raeburn 3601: }
3602: }
1.334 raeburn 3603: } elsif ($context ne 'selfcreate') {
3604: $canshow{'inststatus'} = 1;
1.337 raeburn 3605: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3606: }
1.378 raeburn 3607: foreach my $name ('portfolio','author') {
3608: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3609: }
1.334 raeburn 3610: if ($context eq 'domain') {
1.378 raeburn 3611: foreach my $name ('portfolio','author') {
3612: if ($userenv{$name.'quota'} ne '') {
3613: $oldquota{$name} = $userenv{$name.'quota'};
3614: if ($env{'form.custom_'.$name.'quota'} == 1) {
3615: if ($env{'form.'.$name.'quota'} eq '') {
3616: $newquota{$name} = 0;
3617: } else {
3618: $newquota{$name} = $env{'form.'.$name.'quota'};
3619: $newquota{$name} =~ s/[^\d\.]//g;
3620: }
3621: if ($newquota{$name} != $oldquota{$name}) {
3622: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3623: $changed{$name.'quota'} = 1;
3624: }
3625: }
1.334 raeburn 3626: } else {
1.378 raeburn 3627: if ("a_admin('',\%changeHash,$name)) {
3628: $changed{$name.'quota'} = 1;
3629: $newquota{$name} = $newdefquota{$name};
3630: $newisdefault{$name} = 1;
3631: }
1.334 raeburn 3632: }
1.149 raeburn 3633: } else {
1.378 raeburn 3634: $oldisdefault{$name} = 1;
3635: $oldquota{$name} = $olddefquota{$name};
3636: if ($env{'form.custom_'.$name.'quota'} == 1) {
3637: if ($env{'form.'.$name.'quota'} eq '') {
3638: $newquota{$name} = 0;
3639: } else {
3640: $newquota{$name} = $env{'form.'.$name.'quota'};
3641: $newquota{$name} =~ s/[^\d\.]//g;
3642: }
3643: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3644: $changed{$name.'quota'} = 1;
3645: }
1.334 raeburn 3646: } else {
1.378 raeburn 3647: $newquota{$name} = $newdefquota{$name};
3648: $newisdefault{$name} = 1;
1.334 raeburn 3649: }
1.378 raeburn 3650: }
3651: if ($oldisdefault{$name}) {
3652: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3653: } else {
3654: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3655: }
3656: if ($newisdefault{$name}) {
3657: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3658: } else {
3659: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3660: }
3661: }
1.334 raeburn 3662: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3663: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3664: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3665: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3666: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.406.2.20.2. (raeburn 3667:): my ($isadv,$isauthor) =
3668:): &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
3669:): unless ($isauthor) {
3670:): &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3671:): \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3672:): }
3673:): &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
3674:): \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3675: } else {
1.334 raeburn 3676: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3677: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3678: }
3679: }
1.334 raeburn 3680: foreach my $item (@userinfo) {
3681: if ($env{'form.c'.$item} ne $userenv{$item}) {
3682: $namechanged{$item} = 1;
3683: }
1.204 raeburn 3684: }
1.378 raeburn 3685: foreach my $name ('portfolio','author') {
1.390 bisitz 3686: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3687: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3688: }
1.334 raeburn 3689: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3690: my ($chgresult,$namechgresult);
3691: if (keys(%changed) > 0) {
1.406.2.20.2. (raeburn 3692:): $chgresult =
1.204 raeburn 3693: &Apache::lonnet::put('environment',\%changeHash,
3694: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3695: if ($chgresult eq 'ok') {
1.406.2.20.2. (raeburn 3696:): my ($ca_mgr_del,%ca_mgr_add);
3697:): if ($changed{'managers'}) {
3698:): my (@adds,@dels);
3699:): if ($changeHash{'authormanagers'} eq '') {
3700:): @dels = split(/,/,$userenv{'authormanagers'});
3701:): } elsif ($userenv{'authormanagers'} eq '') {
3702:): @adds = split(/,/,$changeHash{'authormanagers'});
3703:): } else {
3704:): my @old = split(/,/,$userenv{'authormanagers'});
3705:): my @new = split(/,/,$changeHash{'authormanagers'});
3706:): my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
3707:): if (@diffs) {
3708:): foreach my $user (@diffs) {
3709:): if (grep(/^\Q$user\E$/,@old)) {
3710:): push(@dels,$user);
3711:): } elsif (grep(/^\Q$user\E$/,@new)) {
3712:): push(@adds,$user);
3713:): }
3714:): }
3715:): }
3716:): }
3717:): my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
3718:): if (@dels) {
3719:): foreach my $user (@dels) {
3720:): if ($user =~ /^($match_username):($match_domain)$/) {
3721:): &Apache::lonnet::del('environment',[$key],$2,$1);
3722:): }
3723:): }
3724:): my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3725:): if (grep(/^\Q$curruser\E$/,@dels)) {
3726:): $ca_mgr_del = $key;
3727:): }
3728:): }
3729:): if (@adds) {
3730:): foreach my $user (@adds) {
3731:): if ($user =~ /^($match_username):($match_domain)$/) {
3732:): &Apache::lonnet::put('environment',{$key => 1},$2,$1);
3733:): }
3734:): }
3735:): my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3736:): if (grep(/^\Q$curruser\E$/,@adds)) {
3737:): $ca_mgr_add{$key} = 1;
3738:): }
3739:): }
3740:): }
1.267 raeburn 3741: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3742: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.406.2.20.2. (raeburn 3743:): my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
3744:): %userenv);
3745:): my @fromenv = keys(%changed);
3746:): push(@fromenv,'inststatus');
1.270 raeburn 3747: foreach my $key (keys(%changed)) {
1.299 raeburn 3748: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3749: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3750: $newenvhash{'environment.requestcourses.'.$key} =
3751: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3752: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3753: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3754: } else {
1.406.2.20.2. (raeburn 3755:): unless ($got_domdefs) {
3756:): %domdefaults =
3757:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3758:): $got_domdefs = 1;
3759:): }
3760:): unless ($got_userenv) {
3761:): %userenv =
3762:): &Apache::lonnet::userenvironment($env{'user.domain'},
3763:): $env{'user.name'},@fromenv);
3764:): $got_userenv = 1;
3765:): }
1.279 raeburn 3766: $newenvhash{'environment.canrequest.'.$key} =
3767: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3768:): $key,'reload','requestcourses',\%userenv,\%domdefaults);
1.279 raeburn 3769: }
1.362 raeburn 3770: } elsif ($key eq 'requestauthor') {
3771: $newenvhash{'environment.'.$key} = $changeHash{$key};
3772: if ($changeHash{$key}) {
3773: $newenvhash{'environment.canrequest.author'} = 1;
3774: } else {
1.406.2.20.2. (raeburn 3775:): unless ($got_domdefs) {
3776:): %domdefaults =
3777:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3778:): $got_domdefs = 1;
3779:): }
3780:): unless ($got_userenv) {
3781:): %userenv =
3782:): &Apache::lonnet::userenvironment($env{'user.domain'},
3783:): $env{'user.name'},@fromenv);
3784:): $got_userenv = 1;
3785:): }
1.362 raeburn 3786: $newenvhash{'environment.canrequest.author'} =
3787: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3788:): $key,'reload','requestauthor',\%userenv,\%domdefaults);
3789:): }
3790:): } elsif ($key eq 'editors') {
3791:): $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
3792:): if ($env{'form.customeditors'}) {
3793:): $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
3794:): } else {
3795:): unless ($got_domdefs) {
3796:): %domdefaults =
3797:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3798:): $got_domdefs = 1;
3799:): }
3800:): if ($domdefaults{'editors'} ne '') {
3801:): $newenvhash{'environment.editors'} = $domdefaults{'editors'};
3802:): } else {
3803:): $newenvhash{'environment.editors'} = 'edit,xml';
3804:): }
1.362 raeburn 3805: }
1.406.2.20.2. (raeburn 3806:): } elsif ($key eq 'archive') {
3807:): $newenvhash{'environment.author.'.$key} =
3808:): $changeHash{'author.'.$key};
3809:): if ($changeHash{'author.'.$key} ne '') {
3810:): $newenvhash{'environment.canarchive'} =
3811:): $changeHash{'author.'.$key};
3812:): } else {
3813:): unless ($got_domdefs) {
3814:): %domdefaults =
3815:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3816:): $got_domdefs = 1;
3817:): }
3818:): $newenvhash{'environment.canarchive'} =
3819:): $domdefaults{'archive'};
3820:): }
1.275 raeburn 3821: } elsif ($key ne 'quota') {
1.270 raeburn 3822: $newenvhash{'environment.tools.'.$key} =
3823: $changeHash{'tools.'.$key};
1.279 raeburn 3824: if ($changeHash{'tools.'.$key} ne '') {
3825: $newenvhash{'environment.availabletools.'.$key} =
3826: $changeHash{'tools.'.$key};
3827: } else {
1.406.2.20.2. (raeburn 3828:): unless ($got_domdefs) {
3829:): %domdefaults =
3830:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3831:): $got_domdefs = 1;
3832:): }
3833:): unless ($got_userenv) {
3834:): %userenv =
3835:): &Apache::lonnet::userenvironment($env{'user.domain'},
3836:): $env{'user.name'},@fromenv);
3837:): $got_userenv = 1;
3838:): }
1.279 raeburn 3839: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3840: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3841:): $key,'reload','tools',\%userenv,\%domdefaults);
1.279 raeburn 3842: }
1.270 raeburn 3843: }
3844: }
1.271 raeburn 3845: if (keys(%newenvhash)) {
3846: &Apache::lonnet::appenv(\%newenvhash);
3847: }
1.406.2.20.2. (raeburn 3848:): } else {
3849:): if ($ca_mgr_del) {
3850:): &Apache::lonnet::delenv($ca_mgr_del);
3851:): }
3852:): if (keys(%ca_mgr_add)) {
3853:): &Apache::lonnet::appenv(\%ca_mgr_add);
3854:): }
1.267 raeburn 3855: }
1.406.2.20.2. (raeburn 3856:): if ($changed{'aboutme'}) {
3857:): &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3858:): $env{'form.ccdomain'});
3859:): }
1.267 raeburn 3860: }
1.204 raeburn 3861: }
1.334 raeburn 3862: if (keys(%namechanged) > 0) {
1.337 raeburn 3863: foreach my $field (@userinfo) {
3864: $changeHash{$field} = $env{'form.c'.$field};
3865: }
3866: # Make the change
1.204 raeburn 3867: $namechgresult =
3868: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3869: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3870: $changeHash{'firstname'},$changeHash{'middlename'},
3871: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3872: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3873: %userupdate = (
3874: lastname => $env{'form.clastname'},
3875: middlename => $env{'form.cmiddlename'},
3876: firstname => $env{'form.cfirstname'},
3877: generation => $env{'form.cgeneration'},
3878: id => $env{'form.cid'},
3879: );
1.204 raeburn 3880: }
1.334 raeburn 3881: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3882: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3883: # Tell the user we changed the name
1.334 raeburn 3884: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3885: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3886: \%oldsettings, \%oldsettingstext,\%newsettings,
3887: \%newsettingstext);
1.203 raeburn 3888: if ($env{'form.cid'} ne $userenv{'id'}) {
3889: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3890: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3891: if (($recurseid) &&
3892: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3893: my $idresult =
3894: &Apache::lonuserutils::propagate_id_change(
3895: $env{'form.ccuname'},$env{'form.ccdomain'},
3896: \%userupdate);
3897: $r->print('<br />'.$idresult.'<br />');
3898: }
1.196 raeburn 3899: }
1.149 raeburn 3900: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3901: ($env{'form.ccuname'} eq $env{'user.name'})) {
3902: my %newenvhash;
3903: foreach my $key (keys(%changeHash)) {
3904: $newenvhash{'environment.'.$key} = $changeHash{$key};
3905: }
1.238 raeburn 3906: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3907: }
1.28 matthew 3908: } else { # error occurred
1.389 bisitz 3909: $r->print(
3910: '<p class="LC_error">'
3911: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3912: '"'.$env{'form.ccuname'}.'"',
3913: '"'.$env{'form.ccdomain'}.'"')
3914: .'</p>');
1.28 matthew 3915: }
1.334 raeburn 3916: } else { # End of if ($env ... ) logic
1.275 raeburn 3917: # They did not want to change the users name, quota, tool availability,
3918: # or ability to request creation of courses,
1.267 raeburn 3919: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3920: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3921: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3922: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3923: }
1.206 raeburn 3924: if (@mod_disallowed) {
3925: my ($rolestr,$contextname);
3926: if (@longroles > 0) {
3927: $rolestr = join(', ',@longroles);
3928: } else {
3929: $rolestr = &mt('No roles');
3930: }
3931: if ($context eq 'course') {
1.399 bisitz 3932: $contextname = 'course';
1.206 raeburn 3933: } elsif ($context eq 'author') {
1.399 bisitz 3934: $contextname = 'co-author';
1.206 raeburn 3935: }
3936: $r->print(&mt('The following fields were not updated: ').'<ul>');
3937: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3938: foreach my $field (@mod_disallowed) {
3939: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3940: }
1.207 raeburn 3941: $r->print('</ul>');
3942: if (@mod_disallowed == 1) {
1.399 bisitz 3943: $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 3944: } else {
1.399 bisitz 3945: $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 3946: }
1.292 bisitz 3947: my $helplink = 'javascript:helpMenu('."'display'".')';
3948: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3949: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3950: ,'<a href="'.$helplink.'">','</a>')
3951: .'<br />');
1.206 raeburn 3952: }
1.259 bisitz 3953: $r->print('<span class="LC_warning">'
3954: .$no_forceid_alert
3955: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3956: .'</span>');
1.4 www 3957: }
1.367 golterma 3958: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3959: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3960: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3961: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3962: my $linktext = ($crstype eq 'Community' ?
3963: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3964: $r->print(
3965: &Apache::lonhtmlcommon::actionbox([
3966: '<a href="javascript:backPage(document.userupdate)">'
3967: .($crstype eq 'Community' ?
3968: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3969: .'</a>']));
1.220 raeburn 3970: } else {
1.375 raeburn 3971: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3972: if (keys(%namechanged) > 0) {
1.220 raeburn 3973: if ($context eq 'course') {
3974: if (@userroles > 0) {
1.225 raeburn 3975: if ((@rolechanges == 0) ||
3976: (!(grep(/^st$/,@rolechanges)))) {
3977: if (grep(/^st$/,@userroles)) {
3978: my $classlistupdated =
3979: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3980: $cnum,$env{'form.ccdomain'},
3981: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3982: }
1.220 raeburn 3983: }
3984: }
3985: }
3986: }
1.226 raeburn 3987: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3988: $env{'form.ccdomain'});
3989: if ($env{'form.popup'}) {
3990: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3991: } else {
1.367 golterma 3992: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
3993: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
3994: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 3995: }
1.220 raeburn 3996: }
3997: }
3998:
1.334 raeburn 3999: sub display_userinfo {
1.362 raeburn 4000: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
4001: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 4002: $newsetting,$newsettingtext) = @_;
4003: return unless (ref($order) eq 'ARRAY' &&
4004: ref($canshow) eq 'HASH' &&
4005: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 4006: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 4007: ref($usertools) eq 'ARRAY' &&
4008: ref($userenv) eq 'HASH' &&
4009: ref($changedhash) eq 'HASH' &&
4010: ref($oldsetting) eq 'HASH' &&
4011: ref($oldsettingtext) eq 'HASH' &&
4012: ref($newsetting) eq 'HASH' &&
4013: ref($newsettingtext) eq 'HASH');
4014: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 4015: 'ui' => 'User Information',
1.334 raeburn 4016: 'uic' => 'User Information Changed',
4017: 'firstname' => 'First Name',
4018: 'middlename' => 'Middle Name',
4019: 'lastname' => 'Last Name',
4020: 'generation' => 'Generation',
4021: 'id' => 'Student/Employee ID',
4022: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 4023: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 4024: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 4025: 'blog' => 'Blog Availability',
1.361 raeburn 4026: 'webdav' => 'WebDAV Availability',
1.334 raeburn 4027: 'aboutme' => 'Personal Information Page Availability',
4028: 'portfolio' => 'Portfolio Availability',
1.406.2.20.2. (raeburn 4029:): 'portaccess' => 'Portfolio Shareable',
4030:): 'timezone' => 'Can set own Time Zone',
1.334 raeburn 4031: 'official' => 'Can Request Official Courses',
4032: 'unofficial' => 'Can Request Unofficial Courses',
4033: 'community' => 'Can Request Communities',
1.384 raeburn 4034: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 4035: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 4036: 'inststatus' => "Affiliation",
4037: 'prvs' => 'Previous Value:',
1.406.2.20.2. (raeburn 4038:): 'chto' => 'Changed To:',
4039:): 'editors' => "Available Editors in Authoring Space",
4040:): 'managers' => "Co-authors who can add/revoke roles",
4041:): 'archive' => "Managers can download tar.gz file of Authoring Space",
4042:): 'edit' => 'Standard editor (Edit)',
4043:): 'xml' => 'Text editor (EditXML)',
4044:): 'daxe' => 'Daxe editor (Daxe)',
1.334 raeburn 4045: );
4046: if ($changed) {
1.372 raeburn 4047: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 4048: &Apache::loncommon::start_data_table().
4049: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 4050: $r->print("<th> </th>\n");
1.367 golterma 4051: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
4052: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
4053: $r->print(&Apache::loncommon::end_data_table_header_row());
4054: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
4055:
1.334 raeburn 4056: foreach my $item (@userinfo) {
4057: my $value = $env{'form.c'.$item};
1.367 golterma 4058: #show changes only:
1.383 raeburn 4059: unless ($value eq $userenv->{$item}){
1.367 golterma 4060: $r->print(&Apache::loncommon::start_data_table_row());
4061: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 4062: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 4063: $r->print("<td>$value </td>\n");
4064: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 4065: }
4066: }
4067: foreach my $entry (@{$order}) {
1.383 raeburn 4068: if ($canshow->{$entry}) {
1.406.2.20.2. (raeburn 4069:): if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
4070:): ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
1.383 raeburn 4071: my @items;
4072: if ($entry eq 'requestauthor') {
4073: @items = ($entry);
1.406.2.20.2. (raeburn 4074:): } elsif ($entry eq 'authordefaults') {
4075:): @items = ('webdav','managers','editors','archive');
1.383 raeburn 4076: } else {
4077: @items = @{$requestcourses};
1.384 raeburn 4078: }
1.383 raeburn 4079: foreach my $item (@items) {
4080: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
4081: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
4082: $r->print(&Apache::loncommon::start_data_table_row()."\n");
1.406.2.20.2. (raeburn 4083:): $r->print("<td>$lt{$item}</td><td>\n");
4084:): unless ($item eq 'managers') {
4085:): $r->print($oldsetting->{$item});
4086:): }
1.383 raeburn 4087: if ($oldsettingtext->{$item}) {
4088: if ($oldsetting->{$item}) {
1.406.2.20.2. (raeburn 4089:): unless ($item eq 'managers') {
4090:): $r->print(' -- ');
4091:): }
1.383 raeburn 4092: }
4093: $r->print($oldsettingtext->{$item});
4094: }
1.406.2.20.2. (raeburn 4095:): $r->print("</td>\n<td>");
4096:): unless ($item eq 'managers') {
4097:): $r->print($newsetting->{$item});
4098:): }
1.383 raeburn 4099: if ($newsettingtext->{$item}) {
4100: if ($newsetting->{$item}) {
1.406.2.20.2. (raeburn 4101:): unless ($item eq 'managers') {
4102:): $r->print(' -- ');
4103:): }
1.383 raeburn 4104: }
4105: $r->print($newsettingtext->{$item});
4106: }
4107: $r->print("</td>\n");
4108: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4109: }
4110: }
4111: } elsif ($entry eq 'tools') {
4112: foreach my $item (@{$usertools}) {
1.383 raeburn 4113: if ($newsetting->{$item} ne $oldsetting->{$item}) {
4114: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4115: $r->print("<td>$lt{$item}</td>\n");
4116: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
4117: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
4118: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4119: }
4120: }
1.378 raeburn 4121: } elsif ($entry eq 'quota') {
4122: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
4123: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
4124: foreach my $name ('portfolio','author') {
1.383 raeburn 4125: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
4126: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4127: $r->print("<td>$lt{$name.$entry}</td>\n");
4128: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
4129: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
4130: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 4131: }
4132: }
4133: }
1.334 raeburn 4134: } else {
1.383 raeburn 4135: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
4136: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4137: $r->print("<td>$lt{$entry}</td>\n");
4138: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
4139: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
4140: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4141: }
4142: }
4143: }
4144: }
1.367 golterma 4145: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 4146: } else {
4147: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
4148: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 4149: }
4150: return;
4151: }
4152:
1.275 raeburn 4153: sub tool_changes {
4154: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
4155: $changed,$newaccess,$newaccesstext) = @_;
4156: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
4157: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
4158: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
4159: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
4160: return;
4161: }
1.383 raeburn 4162: my %reqdisplay = &requestchange_display();
1.300 raeburn 4163: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 4164: my @options = ('approval','validate','autolimit');
1.306 raeburn 4165: my $optregex = join('|',@options);
1.300 raeburn 4166: my $cdom = $env{'request.role.domain'};
4167: foreach my $tool (@{$usertools}) {
1.383 raeburn 4168: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 4169: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 4170: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 4171: my ($newop,$limit);
1.314 raeburn 4172: if ($env{'form.'.$context.'_'.$tool}) {
4173: $newop = $env{'form.'.$context.'_'.$tool};
4174: if ($newop eq 'autolimit') {
1.383 raeburn 4175: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 4176: $limit =~ s/\D+//g;
4177: $newop .= '='.$limit;
4178: }
4179: }
1.300 raeburn 4180: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 4181: if ($newop) {
4182: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 4183: $changeHash,$context);
4184: if ($changed->{$tool}) {
1.383 raeburn 4185: if ($newop =~ /^autolimit/) {
4186: if ($limit) {
4187: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4188: } else {
4189: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4190: }
4191: } else {
4192: $newaccesstext->{$tool} = $reqdisplay{$newop};
4193: }
1.300 raeburn 4194: } else {
4195: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4196: }
4197: }
4198: } else {
4199: my @curr = split(',',$userenv->{$context.'.'.$tool});
4200: my @new;
4201: my $changedoms;
1.314 raeburn 4202: foreach my $req (@curr) {
4203: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
4204: my $oldop = $1;
1.383 raeburn 4205: if ($oldop =~ /^autolimit=(\d*)/) {
4206: my $limit = $1;
4207: if ($limit) {
4208: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4209: } else {
4210: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4211: }
4212: } else {
4213: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
4214: }
1.314 raeburn 4215: if ($oldop ne $newop) {
4216: $changedoms = 1;
4217: foreach my $item (@curr) {
4218: my ($reqdom,$option) = split(':',$item);
4219: unless ($reqdom eq $cdom) {
4220: push(@new,$item);
4221: }
4222: }
4223: if ($newop) {
4224: push(@new,$cdom.':'.$newop);
1.300 raeburn 4225: }
1.314 raeburn 4226: @new = sort(@new);
1.300 raeburn 4227: }
1.314 raeburn 4228: last;
1.300 raeburn 4229: }
1.314 raeburn 4230: }
4231: if ((!$changedoms) && ($newop)) {
1.300 raeburn 4232: $changedoms = 1;
1.306 raeburn 4233: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 4234: }
4235: if ($changedoms) {
1.314 raeburn 4236: my $newdomstr;
1.300 raeburn 4237: if (@new) {
4238: $newdomstr = join(',',@new);
4239: }
4240: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
4241: $context);
4242: if ($changed->{$tool}) {
4243: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 4244: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 4245: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
4246: $limit =~ s/\D+//g;
4247: if ($limit) {
1.383 raeburn 4248: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 4249: } else {
1.383 raeburn 4250: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 4251: }
1.314 raeburn 4252: } else {
1.306 raeburn 4253: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
4254: }
1.300 raeburn 4255: } else {
1.383 raeburn 4256: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 4257: }
4258: }
4259: }
4260: }
4261: }
4262: return;
4263: }
1.406.2.20.2. (raeburn 4264:): my %tooldesc = &Apache::lonlocal::texthash(
4265:): 'edit' => 'Standard editor (Edit)',
4266:): 'xml' => 'Text editor (EditXML)',
4267:): 'daxe' => 'Daxe editor (Daxe)',
4268:): );
1.275 raeburn 4269: foreach my $tool (@{$usertools}) {
1.383 raeburn 4270: my ($newval,$limit,$envkey);
1.362 raeburn 4271: $envkey = $context.'.'.$tool;
1.306 raeburn 4272: if ($context eq 'requestcourses') {
4273: $newval = $env{'form.crsreq_'.$tool};
4274: if ($newval eq 'autolimit') {
1.383 raeburn 4275: $limit = $env{'form.crsreq_'.$tool.'_limit'};
4276: $limit =~ s/\D+//g;
4277: $newval .= '='.$limit;
1.306 raeburn 4278: }
1.362 raeburn 4279: } elsif ($context eq 'requestauthor') {
4280: $newval = $env{'form.'.$context};
4281: $envkey = $context;
1.406.2.20.2. (raeburn 4282:): } elsif ($context eq 'authordefaults') {
4283:): if ($tool eq 'editors') {
4284:): $envkey = 'authoreditors';
4285:): if ($env{'form.customeditors'} == 1) {
4286:): my @editors;
4287:): my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
4288:): if (@posseditors) {
4289:): foreach my $editor (@posseditors) {
4290:): if (grep(/^\Q$editor\E$/,@posseditors)) {
4291:): unless (grep(/^\Q$editor\E$/,@editors)) {
4292:): push(@editors,$editor);
4293:): }
4294:): }
4295:): }
4296:): }
4297:): if (@editors) {
4298:): $newval = join(',',(sort(@editors)));
4299:): }
4300:): }
4301:): } elsif ($tool eq 'managers') {
4302:): $envkey = 'authormanagers';
4303:): my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
4304:): if (@possibles) {
4305:): my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
4306:): undef,['active','future'],['ca']);
4307:): if (keys(%ca_roles)) {
4308:): my @custommanagers;
4309:): foreach my $user (@possibles) {
4310:): if ($user =~ /^($match_username):($match_domain)$/) {
4311:): if (exists($ca_roles{$user.':ca'})) {
4312:): unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
4313:): push(@custommanagers,$user);
4314:): }
4315:): }
4316:): }
4317:): }
4318:): if (@custommanagers) {
4319:): $newval = join(',',sort(@custommanagers));
4320:): }
4321:): }
4322:): }
4323:): } elsif ($tool eq 'webdav') {
4324:): $envkey = 'tools.webdav';
4325:): $newval = $env{'form.'.$context.'_'.$tool};
4326:): } elsif ($tool eq 'archive') {
4327:): $envkey = 'authorarchive';
4328:): $newval = $env{'form.'.$context.'_'.$tool};
4329:): }
1.314 raeburn 4330: } else {
1.306 raeburn 4331: $newval = $env{'form.'.$context.'_'.$tool};
4332: }
1.362 raeburn 4333: if ($userenv->{$envkey} ne '') {
1.275 raeburn 4334: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 4335: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4336: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
4337: my $currlimit = $1;
4338: if ($currlimit eq '') {
4339: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4340: } else {
4341: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
4342: }
4343: } elsif ($userenv->{$envkey}) {
4344: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
4345: } else {
4346: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4347: }
1.406.2.20.2. (raeburn 4348:): } elsif ($context eq 'authordefaults') {
4349:): if ($tool eq 'managers') {
4350:): if ($userenv->{$envkey} eq '') {
4351:): $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4352:): } else {
4353:): my $managers = $userenv->{$envkey};
4354:): $managers =~ s/,/, /g;
4355:): $oldaccesstext->{$tool} = $managers;
4356:): }
4357:): } elsif ($tool eq 'editors') {
4358:): $oldaccesstext->{$tool} = &mt('can use: [_1]',
4359:): join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4360:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4361:): if ($userenv->{$envkey}) {
4362:): $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4363:): } else {
4364:): $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4365:): }
4366:): }
1.275 raeburn 4367: } else {
1.383 raeburn 4368: if ($userenv->{$envkey}) {
4369: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4370: } else {
4371: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4372: }
1.275 raeburn 4373: }
1.362 raeburn 4374: $changeHash->{$envkey} = $userenv->{$envkey};
1.406.2.20.2. (raeburn 4375:): if (($env{'form.custom'.$tool} == 1) ||
4376:): (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.362 raeburn 4377: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 4378: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4379: $context);
1.275 raeburn 4380: if ($changed->{$tool}) {
4381: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4382: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4383: if ($newval =~ /^autolimit/) {
4384: if ($limit) {
4385: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4386: } else {
4387: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4388: }
4389: } elsif ($newval) {
4390: $newaccesstext->{$tool} = $reqdisplay{$newval};
4391: } else {
4392: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4393: }
1.406.2.20.2. (raeburn 4394:): } elsif ($context eq 'authordefaults') {
4395:): if ($tool eq 'editors') {
4396:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4397:): join(', ', map { $tooldesc{$_} } split(/,/,$changeHash->{$envkey})));
4398:): } elsif ($tool eq 'managers') {
4399:): if ($changeHash->{$envkey} eq '') {
4400:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4401:): } else {
4402:): my $managers = $changeHash->{$envkey};
4403:): $managers =~ s/,/, /g;
4404:): $newaccesstext->{$tool} = $managers;
4405:): }
4406:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4407:): if ($newval) {
4408:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4409:): } else {
4410:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4411:): }
4412:): }
1.275 raeburn 4413: } else {
1.383 raeburn 4414: if ($newval) {
4415: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4416: } else {
4417: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4418: }
1.275 raeburn 4419: }
4420: } else {
4421: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4422: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.406.2.20.2. (raeburn 4423:): if ($userenv->{$envkey} =~ /^autolimit/) {
1.383 raeburn 4424: if ($limit) {
4425: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4426: } else {
4427: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4428: }
1.406.2.20.2. (raeburn 4429:): } elsif ($userenv->{$envkey}) {
4430:): $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
1.383 raeburn 4431: } else {
4432: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4433: }
1.406.2.20.2. (raeburn 4434:): } elsif ($context eq 'authordefaults') {
4435:): if ($tool eq 'editors') {
4436:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4437:): join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4438:): } elsif ($tool eq 'managers') {
4439:): if ($userenv->{$envkey} eq '') {
4440:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4441:): } else {
4442:): my $managers = $userenv->{$envkey};
4443:): $managers =~ s/,/, /g;
4444:): $newaccesstext->{$tool} = $managers;
4445:): }
4446:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4447:): if ($userenv->{$envkey}) {
4448:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4449:): } else {
4450:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4451:): }
4452:): }
1.275 raeburn 4453: } else {
1.383 raeburn 4454: if ($userenv->{$context.'.'.$tool}) {
4455: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4456: } else {
4457: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4458: }
1.275 raeburn 4459: }
4460: }
4461: } else {
4462: $newaccess->{$tool} = $oldaccess->{$tool};
4463: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4464: }
4465: } else {
4466: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
4467: if ($changed->{$tool}) {
4468: $newaccess->{$tool} = &mt('default');
4469: } else {
4470: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4471: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4472: if ($newval =~ /^autolimit/) {
4473: if ($limit) {
4474: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4475: } else {
4476: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4477: }
4478: } elsif ($newval) {
4479: $newaccesstext->{$tool} = $reqdisplay{$newval};
4480: } else {
4481: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4482: }
1.406.2.20.2. (raeburn 4483:): } elsif ($context eq 'authordefaults') {
4484:): if ($tool eq 'editors') {
4485:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4486:): join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4487:): } elsif ($tool eq 'managers') {
4488:): if ($newval eq '') {
4489:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4490:): } else {
4491:): my $managers = $newval;
4492:): $managers =~ s/,/, /g;
4493:): $newaccesstext->{$tool} = $managers;
4494:): }
4495:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4496:): if ($newval) {
4497:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4498:): } else {
4499:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4500:): }
4501:): }
1.275 raeburn 4502: } else {
1.383 raeburn 4503: if ($userenv->{$context.'.'.$tool}) {
4504: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4505: } else {
4506: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4507: }
1.275 raeburn 4508: }
4509: }
4510: }
4511: } else {
4512: $oldaccess->{$tool} = &mt('default');
1.406.2.20.2. (raeburn 4513:): if (($env{'form.custom'.$tool} == 1) ||
4514:): (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.306 raeburn 4515: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4516: $context);
1.275 raeburn 4517: if ($changed->{$tool}) {
4518: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4519: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4520: if ($newval =~ /^autolimit/) {
4521: if ($limit) {
4522: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4523: } else {
4524: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4525: }
4526: } elsif ($newval) {
4527: $newaccesstext->{$tool} = $reqdisplay{$newval};
4528: } else {
4529: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4530: }
1.406.2.20.2. (raeburn 4531:): } elsif ($context eq 'authordefaults') {
4532:): if ($tool eq 'managers') {
4533:): if ($newval eq '') {
4534:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4535:): } else {
4536:): my $managers = $newval;
4537:): $managers =~ s/,/, /g;
4538:): $newaccesstext->{$tool} = $managers;
4539:): }
4540:): } elsif ($tool eq 'editors') {
4541:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4542:): join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4543:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4544:): if ($newval) {
4545:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4546:): } else {
4547:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4548:): }
4549:): }
1.275 raeburn 4550: } else {
1.383 raeburn 4551: if ($newval) {
4552: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4553: } else {
4554: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4555: }
1.275 raeburn 4556: }
4557: } else {
4558: $newaccess->{$tool} = $oldaccess->{$tool};
4559: }
4560: } else {
4561: $newaccess->{$tool} = $oldaccess->{$tool};
4562: }
4563: }
4564: }
4565: return;
4566: }
4567:
1.220 raeburn 4568: sub update_roles {
1.375 raeburn 4569: my ($r,$context,$showcredits) = @_;
1.4 www 4570: my $now=time;
1.225 raeburn 4571: my @rolechanges;
1.220 raeburn 4572: my %disallowed;
1.73 sakharuk 4573: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 4574: foreach my $key (keys(%env)) {
1.135 raeburn 4575: next if (! $env{$key});
1.190 raeburn 4576: next if ($key eq 'form.action');
1.27 matthew 4577: # Revoke roles
1.135 raeburn 4578: if ($key=~/^form\.rev/) {
4579: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 4580: # Revoke standard role
1.170 albertel 4581: my ($scope,$role) = ($1,$2);
4582: my $result =
4583: &Apache::lonnet::revokerole($env{'form.ccdomain'},
4584: $env{'form.ccuname'},
1.239 raeburn 4585: $scope,$role,'','',$context);
1.367 golterma 4586: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4587: &mt('Revoking [_1] in [_2]',
4588: &Apache::lonnet::plaintext($role),
1.372 raeburn 4589: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4590: $result ne "ok").'<br />');
4591: if ($result ne "ok") {
4592: $r->print(&mt('Error: [_1]',$result).'<br />');
4593: }
1.170 albertel 4594: if ($role eq 'st') {
1.202 raeburn 4595: my $result =
1.198 raeburn 4596: &Apache::lonuserutils::classlist_drop($scope,
4597: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4598: $now);
1.367 golterma 4599: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4600: }
1.225 raeburn 4601: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4602: push(@rolechanges,$role);
4603: }
1.196 raeburn 4604: }
1.195 raeburn 4605: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4606: # Revoke custom role
1.369 bisitz 4607: my $result = &Apache::lonnet::revokecustomrole(
4608: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4609: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4610: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4611: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4612: $result ne 'ok').'<br />');
4613: if ($result ne "ok") {
4614: $r->print(&mt('Error: [_1]',$result).'<br />');
4615: }
1.225 raeburn 4616: if (!grep(/^cr$/,@rolechanges)) {
4617: push(@rolechanges,'cr');
4618: }
1.64 www 4619: }
1.135 raeburn 4620: } elsif ($key=~/^form\.del/) {
4621: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4622: # Delete standard role
1.170 albertel 4623: my ($scope,$role) = ($1,$2);
4624: my $result =
4625: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4626: $env{'form.ccuname'},
1.239 raeburn 4627: $scope,$role,$now,0,1,'',
4628: $context);
1.367 golterma 4629: $r->print(&Apache::lonhtmlcommon::confirm_success(
4630: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4631: &Apache::lonnet::plaintext($role),
1.372 raeburn 4632: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4633: $result ne 'ok').'<br />');
4634: if ($result ne "ok") {
4635: $r->print(&mt('Error: [_1]',$result).'<br />');
4636: }
1.367 golterma 4637:
1.170 albertel 4638: if ($role eq 'st') {
1.202 raeburn 4639: my $result =
1.198 raeburn 4640: &Apache::lonuserutils::classlist_drop($scope,
4641: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4642: $now);
1.369 bisitz 4643: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4644: }
1.225 raeburn 4645: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4646: push(@rolechanges,$role);
4647: }
1.116 raeburn 4648: }
1.139 albertel 4649: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4650: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4651: # Delete custom role
1.369 bisitz 4652: my $result =
4653: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4654: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4655: 0,1,$context);
4656: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4657: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4658: $result ne "ok").'<br />');
4659: if ($result ne "ok") {
4660: $r->print(&mt('Error: [_1]',$result).'<br />');
4661: }
1.367 golterma 4662:
1.225 raeburn 4663: if (!grep(/^cr$/,@rolechanges)) {
4664: push(@rolechanges,'cr');
4665: }
1.116 raeburn 4666: }
1.135 raeburn 4667: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4668: my $udom = $env{'form.ccdomain'};
4669: my $uname = $env{'form.ccuname'};
1.116 raeburn 4670: # Re-enable standard role
1.135 raeburn 4671: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4672: my $url = $1;
4673: my $role = $2;
4674: my $logmsg;
4675: my $output;
4676: if ($role eq 'st') {
1.141 albertel 4677: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4678: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4679: my $credits;
4680: if ($showcredits) {
4681: my $defaultcredits =
4682: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4683: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4684: }
4685: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4686: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4687: if ($result eq 'refused' && $logmsg) {
4688: $output = $logmsg;
4689: } else {
1.369 bisitz 4690: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4691: }
1.89 raeburn 4692: } else {
1.372 raeburn 4693: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4694: &Apache::lonnet::plaintext($role),
4695: &Apache::loncommon::show_role_extent($url,$context,'st'),
4696: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4697: }
4698: }
4699: } else {
1.101 albertel 4700: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4701: $env{'form.ccuname'},$url,$role,0,$now,'','',
4702: $context);
1.367 golterma 4703: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4704: &Apache::lonnet::plaintext($role),
4705: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4706: if ($result ne "ok") {
4707: $output .= &mt('Error: [_1]',$result).'<br />';
4708: }
4709: }
1.89 raeburn 4710: $r->print($output);
1.225 raeburn 4711: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4712: push(@rolechanges,$role);
4713: }
1.113 raeburn 4714: }
1.116 raeburn 4715: # Re-enable custom role
1.139 albertel 4716: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4717: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4718: my $result = &Apache::lonnet::assigncustomrole(
4719: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4720: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4721: $r->print(&Apache::lonhtmlcommon::confirm_success(
4722: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4723: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4724: $result ne "ok").'<br />');
4725: if ($result ne "ok") {
4726: $r->print(&mt('Error: [_1]',$result).'<br />');
4727: }
1.225 raeburn 4728: if (!grep(/^cr$/,@rolechanges)) {
4729: push(@rolechanges,'cr');
4730: }
1.116 raeburn 4731: }
1.135 raeburn 4732: } elsif ($key=~/^form\.act/) {
1.101 albertel 4733: my $udom = $env{'form.ccdomain'};
4734: my $uname = $env{'form.ccuname'};
1.141 albertel 4735: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4736: # Activate a custom role
1.83 albertel 4737: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4738: my $url='/'.$one.'/'.$two;
4739: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4740:
1.101 albertel 4741: my $start = ( $env{'form.start_'.$full} ?
4742: $env{'form.start_'.$full} :
1.88 raeburn 4743: $now );
1.101 albertel 4744: my $end = ( $env{'form.end_'.$full} ?
4745: $env{'form.end_'.$full} :
1.88 raeburn 4746: 0 );
4747:
4748: # split multiple sections
4749: my %sections = ();
1.101 albertel 4750: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4751: if ($num_sections == 0) {
1.240 raeburn 4752: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4753: } else {
1.114 albertel 4754: my %curr_groups =
1.117 raeburn 4755: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4756: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4757: if (($sec eq 'none') || ($sec eq 'all') ||
4758: exists($curr_groups{$sec})) {
4759: $disallowed{$sec} = $url;
4760: next;
4761: }
4762: my $securl = $url.'/'.$sec;
1.240 raeburn 4763: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4764: }
4765: }
1.225 raeburn 4766: if (!grep(/^cr$/,@rolechanges)) {
4767: push(@rolechanges,'cr');
4768: }
1.142 raeburn 4769: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4770: # Activate roles for sections with 3 id numbers
4771: # set start, end times, and the url for the class
1.83 albertel 4772: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4773: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4774: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4775: $now );
1.101 albertel 4776: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4777: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4778: 0 );
1.83 albertel 4779: my $url='/'.$one.'/'.$two;
1.88 raeburn 4780: my $type = 'three';
4781: # split multiple sections
4782: my %sections = ();
1.101 albertel 4783: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4784: my $credits;
4785: if ($three eq 'st') {
4786: if ($showcredits) {
4787: my $defaultcredits =
4788: &Apache::lonuserutils::get_defaultcredits($one,$two);
4789: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4790: $credits =~ s/[^\d\.]//g;
4791: if ($credits eq $defaultcredits) {
4792: undef($credits);
4793: }
4794: }
4795: }
1.88 raeburn 4796: if ($num_sections == 0) {
1.375 raeburn 4797: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4798: } else {
1.114 albertel 4799: my %curr_groups =
1.117 raeburn 4800: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4801: my $emptysec = 0;
1.404 raeburn 4802: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4803: $sec =~ s/\W//g;
1.113 raeburn 4804: if ($sec ne '') {
4805: if (($sec eq 'none') || ($sec eq 'all') ||
4806: exists($curr_groups{$sec})) {
4807: $disallowed{$sec} = $url;
4808: next;
4809: }
1.88 raeburn 4810: my $securl = $url.'/'.$sec;
1.375 raeburn 4811: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4812: } else {
4813: $emptysec = 1;
4814: }
4815: }
4816: if ($emptysec) {
1.375 raeburn 4817: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4818: }
1.225 raeburn 4819: }
4820: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4821: push(@rolechanges,$three);
4822: }
1.135 raeburn 4823: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4824: # Activate roles for sections with two id numbers
4825: # set start, end times, and the url for the class
1.101 albertel 4826: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4827: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4828: $now );
1.101 albertel 4829: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4830: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4831: 0 );
1.225 raeburn 4832: my $one = $1;
4833: my $two = $2;
4834: my $url='/'.$one.'/';
1.88 raeburn 4835: # split multiple sections
4836: my %sections = ();
1.225 raeburn 4837: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4838: if ($num_sections == 0) {
1.240 raeburn 4839: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4840: } else {
4841: my $emptysec = 0;
1.404 raeburn 4842: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4843: if ($sec ne '') {
4844: my $securl = $url.'/'.$sec;
1.240 raeburn 4845: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4846: } else {
4847: $emptysec = 1;
4848: }
4849: }
4850: if ($emptysec) {
1.240 raeburn 4851: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4852: }
4853: }
1.225 raeburn 4854: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4855: push(@rolechanges,$two);
4856: }
1.64 www 4857: } else {
1.190 raeburn 4858: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4859: }
1.113 raeburn 4860: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4861: $r->print('<p class="LC_warning">');
1.113 raeburn 4862: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4863: $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 4864: } else {
1.274 bisitz 4865: $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 4866: }
1.274 bisitz 4867: $r->print('</p><p>'
4868: .&mt('Please [_1]go back[_2] and choose a different section name.'
4869: ,'<a href="javascript:history.go(-1)'
4870: ,'</a>')
4871: .'</p><br />'
4872: );
1.113 raeburn 4873: }
4874: }
1.101 albertel 4875: } # End of foreach (keys(%env))
1.75 www 4876: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4877: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4878: if (@rolechanges == 0) {
1.372 raeburn 4879: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4880: }
1.225 raeburn 4881: return @rolechanges;
1.220 raeburn 4882: }
4883:
1.375 raeburn 4884: sub get_user_credits {
4885: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4886: if ($cdom eq '' || $cnum eq '') {
4887: return unless ($env{'request.course.id'});
4888: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4889: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4890: }
4891: my $credits;
4892: my %currhash =
4893: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4894: if (keys(%currhash) > 0) {
4895: my @items = split(/:/,$currhash{$uname.':'.$udom});
4896: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4897: $credits = $items[$crdidx];
4898: $credits =~ s/[^\d\.]//g;
4899: }
4900: if ($credits eq $defaultcredits) {
4901: undef($credits);
4902: }
4903: return $credits;
4904: }
4905:
1.220 raeburn 4906: sub enroll_single_student {
1.375 raeburn 4907: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4908: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4909: $r->print('<h3>');
4910: if ($crstype eq 'Community') {
4911: $r->print(&mt('Enrolling Member'));
4912: } else {
4913: $r->print(&mt('Enrolling Student'));
4914: }
4915: $r->print('</h3>');
1.220 raeburn 4916:
4917: # Remove non alphanumeric values from section
4918: $env{'form.sections'}=~s/\W//g;
4919:
1.375 raeburn 4920: my $credits;
4921: if (($showcredits) && ($env{'form.credits'} ne '')) {
4922: $credits = $env{'form.credits'};
4923: $credits =~ s/[^\d\.]//g;
4924: if ($credits ne '') {
4925: if ($credits eq $defaultcredits) {
4926: undef($credits);
4927: }
4928: }
4929: }
4930:
1.220 raeburn 4931: # Clean out any old student roles the user has in this class.
4932: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4933: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4934: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4935: my $enroll_result =
4936: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4937: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4938: $env{'form.cmiddlename'},$env{'form.clastname'},
4939: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4940: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4941: $credits);
1.220 raeburn 4942: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4943: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4944: if ($env{'form.sections'} ne '') {
4945: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4946: }
4947: my ($showstart,$showend);
4948: if ($startdate <= $now) {
4949: $showstart = &mt('Access starts immediately');
4950: } else {
4951: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4952: }
4953: if ($enddate == 0) {
4954: $showend = &mt('ends: no ending date');
4955: } else {
4956: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4957: }
4958: $r->print('.<br />'.$showstart.'; '.$showend);
4959: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4960: $r->print('<p class="LC_info">');
1.318 raeburn 4961: if ($crstype eq 'Community') {
1.392 raeburn 4962: $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 4963: } else {
1.392 raeburn 4964: $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 4965: }
4966: $r->print('</p>');
1.220 raeburn 4967: }
4968: } else {
4969: $r->print(&mt('unable to enroll').": ".$enroll_result);
4970: }
4971: return;
1.188 raeburn 4972: }
4973:
1.204 raeburn 4974: sub get_defaultquota_text {
4975: my ($settingstatus) = @_;
4976: my $defquotatext;
4977: if ($settingstatus eq '') {
1.383 raeburn 4978: $defquotatext = &mt('default');
1.204 raeburn 4979: } else {
4980: my ($usertypes,$order) =
4981: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4982: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4983: $defquotatext = &mt('default');
1.204 raeburn 4984: } else {
1.383 raeburn 4985: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4986: }
4987: }
4988: return $defquotatext;
4989: }
4990:
1.188 raeburn 4991: sub update_result_form {
4992: my ($uhome) = @_;
4993: my $outcome =
1.367 golterma 4994: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 4995: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 4996: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 4997: }
1.207 raeburn 4998: if ($env{'form.origname'} ne '') {
4999: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
5000: }
1.160 raeburn 5001: foreach my $item ('sortby','seluname','seludom') {
5002: if (exists($env{'form.'.$item})) {
1.188 raeburn 5003: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5004: }
5005: }
1.188 raeburn 5006: if ($uhome eq 'no_host') {
5007: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
5008: }
5009: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 5010: '<input type="hidden" name="currstate" value="" />'."\n".
5011: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 5012: '</form>';
5013: return $outcome;
1.4 www 5014: }
5015:
1.149 raeburn 5016: sub quota_admin {
1.378 raeburn 5017: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 5018: my $quotachanged;
5019: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
5020: # Current user has quota modification privileges
1.267 raeburn 5021: if (ref($changeHash) eq 'HASH') {
5022: $quotachanged = 1;
1.378 raeburn 5023: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 5024: }
1.149 raeburn 5025: }
5026: return $quotachanged;
5027: }
5028:
1.267 raeburn 5029: sub tool_admin {
1.275 raeburn 5030: my ($tool,$settool,$changeHash,$context) = @_;
5031: my $canchange = 0;
1.279 raeburn 5032: if ($context eq 'requestcourses') {
1.275 raeburn 5033: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
5034: $canchange = 1;
5035: }
1.300 raeburn 5036: } elsif ($context eq 'reqcrsotherdom') {
5037: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
5038: $canchange = 1;
5039: }
1.362 raeburn 5040: } elsif ($context eq 'requestauthor') {
5041: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5042: $canchange = 1;
5043: }
1.406.2.20.2. (raeburn 5044:): } elsif ($context eq 'authordefaults') {
5045:): if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5046:): $canchange = 1;
5047:): }
1.275 raeburn 5048: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
5049: # Current user has quota modification privileges
5050: $canchange = 1;
5051: }
1.267 raeburn 5052: my $toolchanged;
1.275 raeburn 5053: if ($canchange) {
1.267 raeburn 5054: if (ref($changeHash) eq 'HASH') {
5055: $toolchanged = 1;
1.362 raeburn 5056: if ($tool eq 'requestauthor') {
5057: $changeHash->{$context} = $settool;
1.406.2.20.2. (raeburn 5058:): } elsif (($tool eq 'managers') || ($tool eq 'editors') || ($tool eq 'archive')) {
5059:): $changeHash->{'author'.$tool} = $settool;
5060:): } elsif ($tool eq 'webdav') {
5061:): $changeHash->{'tools.'.$tool} = $settool;
1.362 raeburn 5062: } else {
5063: $changeHash->{$context.'.'.$tool} = $settool;
5064: }
1.267 raeburn 5065: }
5066: }
5067: return $toolchanged;
5068: }
5069:
1.88 raeburn 5070: sub build_roles {
1.89 raeburn 5071: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 5072: my $num_sections = 0;
5073: if ($sectionstr=~ /,/) {
5074: my @secnums = split/,/,$sectionstr;
1.89 raeburn 5075: if ($role eq 'st') {
5076: $secnums[0] =~ s/\W//g;
5077: $$sections{$secnums[0]} = 1;
5078: $num_sections = 1;
5079: } else {
5080: foreach my $sec (@secnums) {
5081: $sec =~ ~s/\W//g;
1.150 banghart 5082: if (!($sec eq "")) {
1.89 raeburn 5083: if (exists($$sections{$sec})) {
5084: $$sections{$sec} ++;
5085: } else {
5086: $$sections{$sec} = 1;
5087: $num_sections ++;
5088: }
1.88 raeburn 5089: }
5090: }
5091: }
5092: } else {
5093: $sectionstr=~s/\W//g;
5094: unless ($sectionstr eq '') {
5095: $$sections{$sectionstr} = 1;
5096: $num_sections ++;
5097: }
5098: }
1.129 albertel 5099:
1.88 raeburn 5100: return $num_sections;
5101: }
5102:
1.58 www 5103: # ========================================================== Custom Role Editor
5104:
5105: sub custom_role_editor {
1.406.2.14 raeburn 5106: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 5107: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 5108: my ($rolename,$helpitem);
1.324 raeburn 5109: if ($action eq 'new') {
5110: $rolename=$env{'form.newrolename'};
5111: } else {
5112: $rolename=$env{'form.rolename'};
1.59 www 5113: }
5114:
1.324 raeburn 5115: my ($crstype,$context);
5116: if ($env{'request.course.id'}) {
5117: $crstype = &Apache::loncommon::course_type();
5118: $context = 'course';
1.406.2.14 raeburn 5119: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 5120: } else {
5121: $context = 'domain';
1.406.2.5 raeburn 5122: $crstype = 'course';
1.406.2.14 raeburn 5123: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 5124: }
1.351 raeburn 5125:
5126: $rolename=~s/[^A-Za-z0-9]//gs;
5127: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 5128: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
5129: $permission);
1.351 raeburn 5130: return;
5131: }
5132:
1.406.2.5 raeburn 5133: my $formname = 'form1';
5134: my %privs=();
5135: my $body_top = '<h2>';
5136: # ------------------------------------------------------- Does this role exist?
1.59 www 5137: my ($rdummy,$roledef)=
5138: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5139: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 5140: $body_top .= &mt('Existing Role').' "';
1.61 www 5141: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 5142: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
5143: if ($privs{'system'} =~ /bre\&S/) {
5144: if ($context eq 'domain') {
5145: $crstype = 'Course';
5146: } elsif ($crstype eq 'Community') {
5147: $privs{'system'} =~ s/bre\&S//;
5148: }
5149: } elsif ($context eq 'domain') {
5150: $crstype = 'Course';
1.324 raeburn 5151: }
1.59 www 5152: } else {
1.406.2.5 raeburn 5153: $body_top .= &mt('New Role').' "';
5154: $roledef='';
1.59 www 5155: }
1.153 banghart 5156: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 5157:
5158: # ------------------------------------------------------- What can be assigned?
5159: my %full=();
5160: my %levels=(
5161: course => {},
5162: domain => {},
5163: system => {},
5164: );
5165: my %levelscurrent=(
5166: course => {},
5167: domain => {},
5168: system => {},
5169: );
5170: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 5171: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 5172: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5173: my $head_script =
5174: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
5175: \%full,\@templateroles,$jsback);
1.351 raeburn 5176: push (@{$brcrum},
1.406.2.5 raeburn 5177: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 5178: text => "Pick custom role",
5179: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 5180: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 5181: text => "Edit custom role",
5182: faq => 282,
5183: bug => 'Instructor Interface',
1.406.2.14 raeburn 5184: help => $helpitem}
1.351 raeburn 5185: );
5186: my $args = { bread_crumbs => $brcrum,
5187: bread_crumbs_component => 'User Management'};
5188: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
5189: $head_script,$args).
5190: $body_top);
1.406.2.5 raeburn 5191: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
5192: &Apache::lonuserutils::custom_role_header($context,$crstype,
5193: \@templateroles,$prefix));
1.264 bisitz 5194:
1.61 www 5195: $r->print(<<ENDCCF);
5196: <input type="hidden" name="phase" value="set_custom_roles" />
5197: <input type="hidden" name="rolename" value="$rolename" />
5198: ENDCCF
1.406.2.5 raeburn 5199: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
5200: \%levelscurrent,$prefix));
1.135 raeburn 5201: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 5202: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 5203: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 5204: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 5205: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 5206: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 5207: }
1.406.2.5 raeburn 5208:
1.61 www 5209: # ---------------------------------------------------------- Call to definerole
5210: sub set_custom_role {
1.406.2.14 raeburn 5211: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 5212: my $rolename=$env{'form.rolename'};
1.63 www 5213: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 5214: if (!$rolename) {
1.406.2.14 raeburn 5215: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 5216: return;
5217: }
1.160 raeburn 5218: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 5219: my $jscript = '<script type="text/javascript">'
5220: .'// <![CDATA['."\n"
5221: .$jsback."\n"
5222: .'// ]]>'."\n"
5223: .'</script>'."\n";
1.406.2.14 raeburn 5224: my $helpitem = 'Course_Editing_Custom_Roles';
5225: if ($context eq 'domain') {
5226: $helpitem = 'Domain_Editing_Custom_Roles';
5227: }
1.352 raeburn 5228: push(@{$brcrum},
5229: {href => "javascript:backPage(document.customresult,'pickrole','')",
5230: text => "Pick custom role",
5231: faq => 282,
5232: bug => 'Instructor Interface',},
5233: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
5234: text => "Edit custom role",
5235: faq => 282,
5236: bug => 'Instructor Interface',},
5237: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
5238: text => "Result",
5239: faq => 282,
5240: bug => 'Instructor Interface',
1.406.2.14 raeburn 5241: help => $helpitem,}
1.352 raeburn 5242: );
5243: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 5244: bread_crumbs_component => 'User Management'};
1.351 raeburn 5245: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 5246:
1.393 raeburn 5247: my $newrole;
1.61 www 5248: my ($rdummy,$roledef)=
1.110 albertel 5249: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5250:
1.61 www 5251: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 5252: $r->print('<h3>');
1.61 www 5253: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 5254: $r->print(&mt('Existing Role').' "');
1.61 www 5255: } else {
1.73 sakharuk 5256: $r->print(&mt('New Role').' "');
1.61 www 5257: $roledef='';
1.393 raeburn 5258: $newrole = 1;
1.61 www 5259: }
1.188 raeburn 5260: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 5261: # ------------------------------------------------- Assign role and show result
1.61 www 5262:
1.387 bisitz 5263: my $errmsg;
1.406.2.5 raeburn 5264: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
5265: # Assign role and return result
5266: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
5267: $newprivs{'c'});
1.387 bisitz 5268: if ($result ne 'ok') {
5269: $errmsg = ': '.$result;
5270: }
5271: my $message =
5272: &Apache::lonhtmlcommon::confirm_success(
5273: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 5274: if ($env{'request.course.id'}) {
5275: my $url='/'.$env{'request.course.id'};
1.63 www 5276: $url=~s/\_/\//g;
1.387 bisitz 5277: $result =
5278: &Apache::lonnet::assigncustomrole(
5279: $env{'user.domain'},$env{'user.name'},
5280: $url,
5281: $env{'user.domain'},$env{'user.name'},
5282: $rolename,undef,undef,undef,$context);
5283: if ($result ne 'ok') {
5284: $errmsg = ': '.$result;
5285: }
5286: $message .=
5287: '<br />'
5288: .&Apache::lonhtmlcommon::confirm_success(
5289: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 5290: }
1.380 bisitz 5291: $r->print(
1.387 bisitz 5292: &Apache::loncommon::confirmwrapper($message)
5293: .'<br />'
5294: .&Apache::lonhtmlcommon::actionbox([
5295: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
5296: .&mt('Create or edit another custom role')
5297: .'</a>'])
1.380 bisitz 5298: .'<form name="customresult" method="post" action="">'
1.387 bisitz 5299: .&Apache::lonhtmlcommon::echo_form_input([])
5300: .'</form>'
1.380 bisitz 5301: );
1.58 www 5302: }
5303:
1.406.2.20.2. (raeburn 5304:): sub display_coauthor_managers {
5305:): my ($permission) = @_;
5306:): my $output;
5307:): if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5308:): $output = '<form action="/adm/createuser" method="post" name="camanagers">'.
5309:): '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
5310:): '<p>';
5311:): my (@possmanagers,@custommanagers);
5312:): my %userenv =
5313:): &Apache::lonnet::userenvironment($env{'user.domain'},
5314:): $env{'user.name'},
5315:): 'authormanagers');
5316:): my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5317:): ['active','future'],['ca']);
5318:): if (keys(%ca_roles)) {
5319:): foreach my $entry (sort(keys(%ca_roles))) {
5320:): if ($entry =~ /^($match_username\:$match_domain):ca$/) {
5321:): my $user = $1;
5322:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5323:): push(@possmanagers,$user);
5324:): }
5325:): }
5326:): }
5327:): }
5328:): if ($userenv{'authormanagers'} eq '') {
5329:): $output .= &mt('Currently author manages co-author roles');
5330:): } else {
5331:): if (keys(%ca_roles)) {
5332:): foreach my $user (split(/,/,$userenv{'authormanagers'})) {
5333:): if ($user =~ /^($match_username)\:($match_domain)$/) {
5334:): if (exists($ca_roles{$user.':ca'})) {
5335:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5336:): push(@custommanagers,$user);
5337:): }
5338:): }
5339:): }
5340:): }
5341:): }
5342:): if (@custommanagers) {
5343:): $output .= &mt('Co-authors with active or future roles who currently manage co-author roles: [_1]',
5344:): '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @custommanagers));
5345:): } else {
5346:): $output .= &mt('Currently author manages co-author roles');
5347:): }
5348:): }
5349:): $output .= "</p>\n";
5350:): if (@possmanagers) {
5351:): $output .= '<p>'.&mt('If checked, can manage').': ';
5352:): foreach my $user (@possmanagers) {
5353:): my $checked;
5354:): if (grep(/^\Q$user\E$/,@custommanagers)) {
5355:): $checked = ' checked="checked"';
5356:): }
5357:): $output .= '<span style="LC_nobreak"><label>'.
5358:): '<input type="checkbox" name="custommanagers" '.
5359:): 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
5360:): &Apache::loncommon::plainname(split(/:/,$user))." ($user)".'</label></span> '."\n";
5361:): }
5362:): $output .= '<input type="hidden" name="state" value="process" /></p>'."\n".
5363:): '<p><input type="submit" value="'.&mt('Save changes').'" /></p>'."\n";
5364:): } else {
5365:): $output .= '<p>'.&mt('No co-author roles assignable as manager').'</p>';
5366:): }
5367:): $output .= '</form>';
5368:): } else {
5369:): $output = '<span class="LC_warning">'.
5370:): &mt('You do not have permission to perform this action').
5371:): '</span>';
5372:): }
5373:): return $output;
5374:): }
5375:):
5376:): sub update_coauthor_managers {
5377:): my ($permission) = @_;
5378:): my $output;
5379:): if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5380:): my ($current,$newval,@possibles,@managers);
5381:): my %userenv =
5382:): &Apache::lonnet::userenvironment($env{'user.domain'},
5383:): $env{'user.name'},
5384:): 'authormanagers');
5385:): $current = $userenv{'authormanagers'};
5386:): @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
5387:): if (@possibles) {
5388:): my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5389:): ['active','future'],['ca']);
5390:): if (keys(%ca_roles)) {
5391:): foreach my $user (@possibles) {
5392:): if ($user =~ /^($match_username):($match_domain)$/) {
5393:): if (exists($ca_roles{$user.':ca'})) {
5394:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5395:): push(@managers,$user);
5396:): }
5397:): }
5398:): }
5399:): }
5400:): if (@managers) {
5401:): $newval = join(',',sort(@managers));
5402:): }
5403:): }
5404:): }
5405:): if ($current eq $newval) {
5406:): $output = &mt('No changes made to management of co-author roles');
5407:): } else {
5408:): my $chgresult =
5409:): &Apache::lonnet::put('environment',{'authormanagers' => $newval},
5410:): $env{'user.domain'},$env{'user.name'});
5411:): if ($chgresult eq 'ok') {
5412:): &Apache::lonnet::appenv({'environment.authormanagers' => $newval});
5413:): my (@adds,@dels);
5414:): if ($newval eq '') {
5415:): @dels = split(/,/,$current);
5416:): } elsif ($current eq '') {
5417:): @adds = @managers;
5418:): } else {
5419:): my @old = split(/,/,$current);
5420:): my @diffs = &Apache::loncommon::compare_arrays(\@old,\@managers);
5421:): if (@diffs) {
5422:): foreach my $user (@diffs) {
5423:): if (grep(/^\Q$user\E$/,@old)) {
5424:): push(@dels,$user);
5425:): } elsif (grep(/^\Q$user\E$/,@managers)) {
5426:): push(@adds,$user);
5427:): }
5428:): }
5429:): }
5430:): }
5431:): my $key = "internal.manager./$env{'user.domain'}/$env{'user.name'}";
5432:): if (@dels) {
5433:): foreach my $user (@dels) {
5434:): if ($user =~ /^($match_username):($match_domain)$/) {
5435:): &Apache::lonnet::del('environment',[$key],$2,$1);
5436:): }
5437:): }
5438:): }
5439:): if (@adds) {
5440:): foreach my $user (@adds) {
5441:): if ($user =~ /^($match_username):($match_domain)$/) {
5442:): &Apache::lonnet::put('environment',{$key => 1},$2,$1);
5443:): }
5444:): }
5445:): }
5446:): if ($newval eq '') {
5447:): $output = &mt('Management of co-authors set to be author-only');
5448:): } else {
5449:): $output .= &mt('Co-authors who can manage co-author roles set to: [_1]',
5450:): '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @managers));
5451:): }
5452:): }
5453:): }
5454:): } else {
5455:): $output = '<span class="LC_warning">'.
5456:): &mt('You do not have permission to perform this action').
5457:): '</span>';
5458:): }
5459:): return $output;
5460:): }
5461:):
1.2 www 5462: # ================================================================ Main Handler
5463: sub handler {
5464: my $r = shift;
5465: if ($r->header_only) {
1.68 www 5466: &Apache::loncommon::content_type($r,'text/html');
1.2 www 5467: $r->send_http_header;
5468: return OK;
5469: }
1.406.2.14 raeburn 5470: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
5471:
1.190 raeburn 5472: if ($env{'request.course.id'}) {
5473: $context = 'course';
1.318 raeburn 5474: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 5475: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 5476: $context = 'author';
1.406.2.20.2. (raeburn 5477:): } elsif ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$}) {
5478:): $context = 'coauthor';
1.190 raeburn 5479: } else {
5480: $context = 'domain';
5481: }
1.375 raeburn 5482:
1.406.2.14 raeburn 5483: my ($permission,$allowed) =
5484: &Apache::lonuserutils::get_permission($context,$crstype);
1.406.2.20.2. (raeburn 5485:): if (($context eq 'coauthor') && ($allowed)) {
5486:): $context = 'author';
5487:): }
1.406.2.14 raeburn 5488:
5489: if ($allowed) {
5490: my @allhelp;
5491: if ($context eq 'course') {
5492: $cid = $env{'request.course.id'};
5493: $cdom = $env{'course.'.$cid.'.domain'};
5494: $cnum = $env{'course.'.$cid.'.num'};
5495:
5496: if ($permission->{'cusr'}) {
5497: push(@allhelp,'Course_Create_Class_List');
5498: }
5499: if ($permission->{'view'} || $permission->{'cusr'}) {
5500: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
5501: }
5502: if ($permission->{'custom'}) {
5503: push(@allhelp,'Course_Editing_Custom_Roles');
5504: }
5505: if ($permission->{'cusr'}) {
5506: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
5507: }
5508: unless ($permission->{'cusr_section'}) {
5509: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
5510: push(@allhelp,'Course_Automated_Enrollment');
5511: }
1.406.2.20.2. (raeburn 5512:): if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.406.2.14 raeburn 5513: push(@allhelp,'Course_Approve_Selfenroll');
5514: }
5515: }
5516: if ($permission->{'grp_manage'}) {
5517: push(@allhelp,'Course_Manage_Group');
5518: }
5519: if ($permission->{'view'} || $permission->{'cusr'}) {
5520: push(@allhelp,'Course_User_Logs');
5521: }
5522: } elsif ($context eq 'author') {
5523: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5524: 'Author_View_Coauthor_List','Author_User_Logs'));
1.406.2.20.2. (raeburn 5525:): } elsif ($context eq 'coauthor') {
5526:): if ($permission->{'cusr'}) {
5527:): push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5528:): 'Author_View_Coauthor_List','Author_User_Logs'));
5529:): } elsif ($permission->{'view'}) {
5530:): push(@allhelp,'Author_View_Coauthor_List');
5531:): }
1.406.2.14 raeburn 5532: } else {
5533: if ($permission->{'cusr'}) {
5534: push(@allhelp,'Domain_Change_Privileges');
5535: if ($permission->{'activity'}) {
5536: push(@allhelp,'Domain_User_Access_Logs');
5537: }
5538: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
5539: if ($permission->{'custom'}) {
5540: push(@allhelp,'Domain_Editing_Custom_Roles');
5541: }
5542: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
5543: } elsif ($permission->{'view'}) {
5544: push(@allhelp,'Domain_View_Privileges');
5545: if ($permission->{'activity'}) {
5546: push(@allhelp,'Domain_User_Access_Logs');
5547: }
5548: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
5549: }
5550: }
5551: if (@allhelp) {
5552: $allhelpitems = join(',',@allhelp);
5553: }
5554: }
5555:
1.190 raeburn 5556: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 5557: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.406.2.20.2. (raeburn 5558:): 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue',
5559:): 'forceedit']);
1.190 raeburn 5560: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 5561: my $args;
5562: my $brcrum = [];
5563: my $bread_crumbs_component = 'User Management';
1.391 raeburn 5564: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 5565: $brcrum = [{href=>"/adm/createuser",
5566: text=>"User Management",
1.406.2.14 raeburn 5567: help=>$allhelpitems}
1.351 raeburn 5568: ];
1.202 raeburn 5569: }
1.190 raeburn 5570: if (!$allowed) {
1.358 raeburn 5571: if ($context eq 'course') {
5572: $r->internal_redirect('/adm/viewclasslist');
5573: return OK;
1.406.2.20.2. (raeburn 5574:): } elsif ($context eq 'coauthor') {
5575:): $r->internal_redirect('/adm/viewcoauthors');
5576:): return OK;
1.358 raeburn 5577: }
1.190 raeburn 5578: $env{'user.error.msg'}=
5579: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
5580: "or view user status.";
5581: return HTTP_NOT_ACCEPTABLE;
5582: }
5583:
5584: &Apache::loncommon::content_type($r,'text/html');
5585: $r->send_http_header;
5586:
1.375 raeburn 5587: my $showcredits;
5588: if ((($context eq 'course') && ($crstype eq 'Course')) ||
5589: ($context eq 'domain')) {
5590: my %domdefaults =
5591: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
5592: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
5593: $showcredits = 1;
5594: }
5595: }
5596:
1.190 raeburn 5597: # Main switch on form.action and form.state, as appropriate
5598: if (! exists($env{'form.action'})) {
1.351 raeburn 5599: $args = {bread_crumbs => $brcrum,
5600: bread_crumbs_component => $bread_crumbs_component};
5601: $r->print(&header(undef,$args));
1.318 raeburn 5602: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5603: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 5604: my $helpitem = 'Course_Create_Class_List';
5605: if ($context eq 'author') {
5606: $helpitem = 'Author_Create_Coauthor_List';
5607: } elsif ($context eq 'domain') {
5608: $helpitem = 'Domain_Create_Users';
5609: }
1.351 raeburn 5610: push(@{$brcrum},
5611: { href => '/adm/createuser?action=upload&state=',
5612: text => 'Upload Users List',
1.406.2.14 raeburn 5613: help => $helpitem,
1.351 raeburn 5614: });
5615: $bread_crumbs_component = 'Upload Users List';
5616: $args = {bread_crumbs => $brcrum,
5617: bread_crumbs_component => $bread_crumbs_component};
5618: $r->print(&header(undef,$args));
1.190 raeburn 5619: $r->print('<form name="studentform" method="post" '.
5620: 'enctype="multipart/form-data" '.
5621: ' action="/adm/createuser">'."\n");
5622: if (! exists($env{'form.state'})) {
5623: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5624: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 5625: my $result =
5626: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5627: $permission,
5628: $crstype,$showcredits);
5629: if ($result eq 'missingdata') {
5630: delete($env{'form.state'});
5631: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5632: }
1.190 raeburn 5633: } elsif ($env{'form.state'} eq 'enrolling') {
5634: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 5635: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5636: $permission,
5637: $showcredits);
5638: if ($result eq 'missingdata') {
5639: delete($env{'form.state'});
5640: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5641: } elsif ($result eq 'invalidhome') {
5642: $env{'form.state'} = 'got_file';
5643: delete($env{'form.lcserver'});
5644: my $result =
5645: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5646: $crstype,$showcredits);
5647: if ($result eq 'missingdata') {
5648: delete($env{'form.state'});
5649: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5650: }
5651: }
5652: } else {
5653: delete($env{'form.state'});
5654: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5655: }
5656: } else {
5657: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5658: }
1.406.2.15 raeburn 5659: $r->print('</form>');
1.406.2.5 raeburn 5660: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5661: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 5662: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 5663: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5664: my $phase = $env{'form.phase'};
5665: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5666: &Apache::loncreateuser::restore_prev_selections();
5667: my $srch;
5668: foreach my $item (@search) {
5669: $srch->{$item} = $env{'form.'.$item};
5670: }
1.207 raeburn 5671: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 5672: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5673: if ($env{'form.phase'} eq 'createnewuser') {
5674: my $response;
5675: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5676: my $response =
5677: '<span class="LC_warning">'
5678: .&mt('You must specify a valid username. Only the following are allowed:'
5679: .' letters numbers - . @')
5680: .'</span>';
1.221 raeburn 5681: $env{'form.phase'} = '';
1.375 raeburn 5682: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 5683: $crstype,$brcrum,$permission);
1.207 raeburn 5684: } else {
5685: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5686: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5687: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5688: $srch,$response,$context,
1.375 raeburn 5689: $permission,$crstype,$brcrum,
5690: $showcredits);
1.207 raeburn 5691: }
5692: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5693: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5694: &user_search_result($context,$srch);
1.190 raeburn 5695: if ($env{'form.currstate'} eq 'modify') {
5696: $currstate = $env{'form.currstate'};
5697: }
5698: if ($currstate eq 'select') {
5699: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5700: \@search,$context,undef,$crstype,
5701: $brcrum);
1.406.2.5 raeburn 5702: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5703: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5704: if (($srch->{'srchby'} eq 'uname') &&
5705: ($srch->{'srchtype'} eq 'exact')) {
5706: $ccuname = $srch->{'srchterm'};
5707: $ccdomain= $srch->{'srchdomain'};
5708: } else {
5709: my @matchedunames = keys(%{$results});
5710: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5711: }
5712: $ccuname =&LONCAPA::clean_username($ccuname);
5713: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 5714: if ($env{'form.action'} eq 'accesslogs') {
5715: my $uhome;
5716: if (($ccuname ne '') && ($ccdomain ne '')) {
5717: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5718: }
5719: if (($uhome eq '') || ($uhome eq 'no_host')) {
5720: $env{'form.phase'} = '';
5721: undef($forcenewuser);
5722: #if ($response) {
5723: # unless ($response =~ m{\Q<br /><br />\E$}) {
5724: # $response .= '<br /><br />';
5725: # }
5726: #}
5727: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 5728: $forcenewuser,$crstype,$brcrum,
5729: $permission);
1.406.2.5 raeburn 5730: } else {
5731: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5732: }
5733: } else {
5734: if ($env{'form.forcenewuser'}) {
5735: $response = '';
5736: }
5737: &print_user_modification_page($r,$ccuname,$ccdomain,
5738: $srch,$response,$context,
5739: $permission,$crstype,$brcrum);
1.190 raeburn 5740: }
5741: } elsif ($currstate eq 'query') {
1.351 raeburn 5742: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 5743: } else {
1.229 raeburn 5744: $env{'form.phase'} = '';
1.207 raeburn 5745: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 5746: $forcenewuser,$crstype,$brcrum,
5747: $permission);
1.190 raeburn 5748: }
5749: } elsif ($env{'form.phase'} eq 'userpicked') {
5750: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
5751: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 5752: if ($env{'form.action'} eq 'accesslogs') {
5753: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5754: } else {
5755: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
5756: $context,$permission,$crstype,
5757: $brcrum);
5758: }
5759: } elsif ($env{'form.action'} eq 'accesslogs') {
5760: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
5761: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
5762: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 5763: }
5764: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.406.2.17 raeburn 5765: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 5766: } else {
1.351 raeburn 5767: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 5768: $brcrum,$permission);
1.190 raeburn 5769: }
5770: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 5771: my $prefix;
1.190 raeburn 5772: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 5773: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5774: } else {
1.406.2.14 raeburn 5775: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5776: }
1.362 raeburn 5777: } elsif (($env{'form.action'} eq 'processauthorreq') &&
5778: ($permission->{'cusr'}) &&
5779: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5780: push(@{$brcrum},
5781: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 5782: text => 'Authoring Space requests',
1.362 raeburn 5783: help => 'Domain_Role_Approvals'});
5784: $bread_crumbs_component = 'Authoring requests';
5785: if ($env{'form.state'} eq 'done') {
5786: push(@{$brcrum},
5787: {href => '/adm/createuser?action=authorreqqueue',
5788: text => 'Result',
5789: help => 'Domain_Role_Approvals'});
5790: $bread_crumbs_component = 'Authoring request result';
5791: }
5792: $args = { bread_crumbs => $brcrum,
5793: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5794: my $js = &usernamerequest_javascript();
5795: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5796: if (!exists($env{'form.state'})) {
5797: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5798: $env{'request.role.domain'}));
5799: } elsif ($env{'form.state'} eq 'done') {
5800: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
5801: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
5802: $env{'request.role.domain'}));
5803: }
1.391 raeburn 5804: } elsif (($env{'form.action'} eq 'processusernamereq') &&
5805: ($permission->{'cusr'}) &&
5806: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5807: push(@{$brcrum},
5808: {href => '/adm/createuser?action=processusernamereq',
5809: text => 'LON-CAPA account requests',
5810: help => 'Domain_Username_Approvals'});
5811: $bread_crumbs_component = 'Account requests';
5812: if ($env{'form.state'} eq 'done') {
5813: push(@{$brcrum},
5814: {href => '/adm/createuser?action=usernamereqqueue',
5815: text => 'Result',
5816: help => 'Domain_Username_Approvals'});
5817: $bread_crumbs_component = 'LON-CAPA account request result';
5818: }
5819: $args = { bread_crumbs => $brcrum,
5820: bread_crumbs_component => $bread_crumbs_component};
5821: my $js = &usernamerequest_javascript();
5822: $r->print(&header(&add_script($js),$args));
5823: if (!exists($env{'form.state'})) {
5824: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
5825: $env{'request.role.domain'}));
5826: } elsif ($env{'form.state'} eq 'done') {
5827: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
5828: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
5829: $env{'request.role.domain'}));
5830: }
5831: } elsif (($env{'form.action'} eq 'displayuserreq') &&
5832: ($permission->{'cusr'})) {
5833: my $dom = $env{'form.domain'};
5834: my $uname = $env{'form.username'};
5835: my $warning;
5836: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
5837: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5838: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5839: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5840: if ($uhome eq 'no_host') {
5841: my $queue = $env{'form.queue'};
5842: my $reqkey = &escape($uname).'_'.$queue;
5843: my $namespace = 'usernamequeue';
5844: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5845: my %queued =
5846: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5847: unless ($queued{$reqkey}) {
5848: $warning = &mt('No information was found for this LON-CAPA account request.');
5849: }
5850: } else {
5851: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5852: }
5853: } else {
5854: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5855: }
5856: } else {
5857: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5858: }
5859: } else {
5860: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5861: }
5862: my $args = { only_body => 1 };
5863: $r->print(&header(undef,$args).
5864: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5865: if ($warning ne '') {
5866: $r->print('<div class="LC_warning">'.$warning.'</div>');
5867: } else {
5868: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5869: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5870: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5871: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5872: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5873: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5874: my %info =
5875: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5876: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5877: my $usertype = $info{$uname}{'inststatus'};
5878: unless ($usertype) {
5879: $usertype = 'default';
5880: }
1.406.2.16 raeburn 5881: my ($showstatus,$showemail,$pickstart);
5882: my $numextras = 0;
5883: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5884: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5885: if (ref($usertypes) eq 'HASH') {
5886: if ($usertypes->{$usertype}) {
5887: $showstatus = $usertypes->{$usertype};
5888: } else {
5889: $showstatus = $othertitle;
5890: }
5891: if ($showstatus) {
5892: $numextras ++;
5893: }
5894: }
5895: }
5896: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5897: $showemail = $info{$uname}{'email'};
5898: $numextras ++;
5899: }
1.396 raeburn 5900: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5901: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16 raeburn 5902: $pickstart = 1;
1.396 raeburn 5903: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16 raeburn 5904: my ($num,$count);
1.396 raeburn 5905: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16 raeburn 5906: $count += $numextras;
1.396 raeburn 5907: foreach my $field (@{$infofields}) {
5908: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5909: next unless ($infotitles->{$field});
5910: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5911: $info{$uname}{$field});
5912: $num ++;
1.406.2.16 raeburn 5913: unless ($count == $num) {
1.396 raeburn 5914: $r->print(&Apache::lonhtmlcommon::row_closure());
5915: }
5916: }
1.406.2.16 raeburn 5917: }
5918: }
5919: if ($numextras) {
5920: unless ($pickstart) {
5921: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5922: $pickstart = 1;
5923: }
5924: if ($showemail) {
5925: my $closure = '';
5926: unless ($showstatus) {
5927: $closure = 1;
1.391 raeburn 5928: }
1.406.2.16 raeburn 5929: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5930: $showemail.
5931: &Apache::lonhtmlcommon::row_closure($closure));
5932: }
5933: if ($showstatus) {
5934: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5935: $showstatus.
5936: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5937: }
5938: }
1.406.2.16 raeburn 5939: if ($pickstart) {
5940: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5941: } else {
5942: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5943: }
5944: } else {
5945: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5946: }
5947: }
5948: }
5949: }
5950: }
1.406.2.16 raeburn 5951: $r->print(&close_popup_form());
1.207 raeburn 5952: } elsif (($env{'form.action'} eq 'listusers') &&
5953: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5954: my $helpitem = 'Course_View_Class_List';
5955: if ($context eq 'author') {
5956: $helpitem = 'Author_View_Coauthor_List';
5957: } elsif ($context eq 'domain') {
5958: $helpitem = 'Domain_View_Users_List';
5959: }
1.202 raeburn 5960: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5961: push(@{$brcrum},
5962: {href => '/adm/createuser?action=listusers',
5963: text => "List Users"},
5964: {href => "/adm/createuser",
5965: text => "Result",
1.406.2.14 raeburn 5966: help => $helpitem});
1.351 raeburn 5967: $bread_crumbs_component = 'Update Users';
5968: $args = {bread_crumbs => $brcrum,
5969: bread_crumbs_component => $bread_crumbs_component};
5970: $r->print(&header(undef,$args));
1.202 raeburn 5971: my $setting = $env{'form.roletype'};
5972: my $choice = $env{'form.bulkaction'};
5973: if ($permission->{'cusr'}) {
1.336 raeburn 5974: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5975: } else {
5976: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5977: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5978: }
5979: } else {
1.351 raeburn 5980: push(@{$brcrum},
5981: {href => '/adm/createuser?action=listusers',
5982: text => "List Users",
1.406.2.14 raeburn 5983: help => $helpitem});
1.351 raeburn 5984: $bread_crumbs_component = 'List Users';
5985: $args = {bread_crumbs => $brcrum,
5986: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5987: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5988: my $formname = 'studentform';
1.364 raeburn 5989: my $hidecall = "hide_searching();";
1.321 raeburn 5990: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5991: ($env{'form.roletype'} eq 'community'))) {
5992: if ($env{'form.roletype'} eq 'course') {
5993: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
5994: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
5995: $formname);
5996: } elsif ($env{'form.roletype'} eq 'community') {
5997: $cb_jscript =
5998: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
5999: my %elements = (
6000: coursepick => 'radio',
6001: coursetotal => 'text',
6002: courselist => 'text',
6003: );
6004: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
6005: }
1.364 raeburn 6006: $jscript .= &verify_user_display($context)."\n".
6007: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 6008: my $js = &add_script($jscript).$cb_jscript;
6009: my $loadcode =
6010: &Apache::lonuserutils::course_selector_loadcode($formname);
6011: if ($loadcode ne '') {
1.364 raeburn 6012: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
6013: } else {
6014: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 6015: }
1.351 raeburn 6016: $r->print(&header($js,$args));
1.191 raeburn 6017: } else {
1.364 raeburn 6018: $args->{add_entries} = {onload => $hidecall};
6019: $jscript = &verify_user_display($context).
6020: &Apache::loncommon::check_uncheck_jscript();
6021: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 6022: }
1.202 raeburn 6023: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 6024: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
6025: $showcredits);
1.191 raeburn 6026: }
1.213 raeburn 6027: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 6028: my $brtext;
6029: if ($crstype eq 'Community') {
6030: $brtext = 'Drop Members';
6031: } else {
6032: $brtext = 'Drop Students';
6033: }
1.351 raeburn 6034: push(@{$brcrum},
6035: {href => '/adm/createuser?action=drop',
6036: text => $brtext,
6037: help => 'Course_Drop_Student'});
6038: if ($env{'form.state'} eq 'done') {
6039: push(@{$brcrum},
6040: {href=>'/adm/createuser?action=drop',
6041: text=>"Result"});
6042: }
6043: $bread_crumbs_component = $brtext;
6044: $args = {bread_crumbs => $brcrum,
6045: bread_crumbs_component => $bread_crumbs_component};
6046: $r->print(&header(undef,$args));
1.213 raeburn 6047: if (!exists($env{'form.state'})) {
1.318 raeburn 6048: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 6049: } elsif ($env{'form.state'} eq 'done') {
6050: &Apache::lonuserutils::update_user_list($r,$context,undef,
6051: $env{'form.action'});
6052: }
1.202 raeburn 6053: } elsif ($env{'form.action'} eq 'dateselect') {
6054: if ($permission->{'cusr'}) {
1.351 raeburn 6055: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 6056: &Apache::lonuserutils::date_section_selector($context,$permission,
6057: $crstype,$showcredits));
1.202 raeburn 6058: } else {
1.351 raeburn 6059: $r->print(&header(undef,{'no_nav_bar' => 1}).
6060: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 6061: }
1.237 raeburn 6062: } elsif ($env{'form.action'} eq 'selfenroll') {
1.406.2.20.2. (raeburn 6063:): my %currsettings;
6064:): if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
6065:): %currsettings = (
1.398 raeburn 6066: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
6067: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
6068: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
6069: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
6070: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
6071: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
6072: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
6073: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
6074: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
6075: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
6076: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
6077: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
6078: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 6079: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 6080: );
1.406.2.20.2. (raeburn 6081:): }
6082:): if ($permission->{selfenrolladmin}) {
1.398 raeburn 6083: push(@{$brcrum},
6084: {href => '/adm/createuser?action=selfenroll',
6085: text => "Configure Self-enrollment",
6086: help => 'Course_Self_Enrollment'});
6087: if (!exists($env{'form.state'})) {
6088: $args = { bread_crumbs => $brcrum,
6089: bread_crumbs_component => 'Configure Self-enrollment'};
6090: $r->print(&header(undef,$args));
6091: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6092: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
6093: } elsif ($env{'form.state'} eq 'done') {
6094: push (@{$brcrum},
6095: {href=>'/adm/createuser?action=selfenroll',
6096: text=>"Result"});
6097: $args = { bread_crumbs => $brcrum,
6098: bread_crumbs_component => 'Self-enrollment result'};
6099: $r->print(&header(undef,$args));
6100: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 6101: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 6102: }
1.406.2.20.2. (raeburn 6103:): } elsif ($permission->{selfenrollview}) {
6104:): push(@{$brcrum},
6105:): {href => '/adm/createuser?action=selfenroll',
6106:): text => "View Self-enrollment configuration",
6107:): help => 'Course_Self_Enrollment'});
6108:): $args = { bread_crumbs => $brcrum,
6109:): bread_crumbs_component => 'Self-enrollment Settings'};
6110:): $r->print(&header(undef,$args));
6111:): $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6112:): &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 6113: } else {
6114: $r->print(&header(undef,{'no_nav_bar' => 1}).
6115: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 6116: }
1.277 raeburn 6117: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 6118: if ($permission->{selfenrolladmin}) {
1.351 raeburn 6119: push(@{$brcrum},
6120: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 6121: text => 'Enrollment requests',
1.406.2.14 raeburn 6122: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 6123: $bread_crumbs_component = 'Enrollment requests';
6124: if ($env{'form.state'} eq 'done') {
6125: push(@{$brcrum},
6126: {href => '/adm/createuser?action=selfenrollqueue',
6127: text => 'Result',
1.406.2.14 raeburn 6128: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 6129: $bread_crumbs_component = 'Enrollment result';
6130: }
6131: $args = { bread_crumbs => $brcrum,
6132: bread_crumbs_component => $bread_crumbs_component};
6133: $r->print(&header(undef,$args));
6134: my $coursedesc = $env{'course.'.$cid.'.description'};
6135: if (!exists($env{'form.state'})) {
6136: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
6137: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
6138: $cdom,$cnum));
6139: } elsif ($env{'form.state'} eq 'done') {
6140: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
6141: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
6142: $cdom,$cnum,$coursedesc));
6143: }
6144: } else {
6145: $r->print(&header(undef,{'no_nav_bar' => 1}).
6146: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 6147: }
1.239 raeburn 6148: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 6149: if ($permission->{cusr} || $permission->{view}) {
6150: &print_userchangelogs_display($r,$context,$permission,$brcrum);
6151: } else {
6152: $r->print(&header(undef,{'no_nav_bar' => 1}).
6153: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
6154: }
1.406.2.10 raeburn 6155: } elsif ($env{'form.action'} eq 'helpdesk') {
1.406.2.20.2. (raeburn 6156:): if (($permission->{'owner'} || $permission->{'co-owner'}) &&
6157:): ($permission->{'cusr'} || $permission->{'view'})) {
1.406.2.10 raeburn 6158: if ($env{'form.state'} eq 'process') {
6159: if ($permission->{'owner'}) {
6160: &update_helpdeskaccess($r,$permission,$brcrum);
6161: } else {
6162: &print_helpdeskaccess_display($r,$permission,$brcrum);
6163: }
6164: } else {
6165: &print_helpdeskaccess_display($r,$permission,$brcrum);
6166: }
6167: } else {
6168: $r->print(&header(undef,{'no_nav_bar' => 1}).
6169: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
6170: }
1.406.2.20.2. (raeburn 6171:): } elsif ($env{'form.action'} eq 'camanagers') {
6172:): if (($permission->{cusr}) && ($context eq 'author')) {
6173:): push(@{$brcrum},
6174:): {href => '/adm/createuser?action=camanagers',
6175:): text => 'Co-author Managers',
6176:): help => 'Author_Manage_Coauthors'});
6177:): if ($env{'form.state'} eq 'process') {
6178:): push(@{$brcrum},
6179:): {href => '/adm/createuser?action=camanagers',
6180:): text => 'Result',
6181:): help => 'Author_Manage_Coauthors'});
6182:): }
6183:): $args = { bread_crumbs => $brcrum };
6184:): $r->print(&header(undef,$args));
6185:): my $coursedesc = $env{'course.'.$cid.'.description'};
6186:): if (!exists($env{'form.state'})) {
6187:): $r->print('<h3>'.&mt('Co-author Management').'</h3>'."\n".
6188:): &display_coauthor_managers($permission));
6189:): } elsif ($env{'form.state'} eq 'process') {
6190:): $r->print('<h3>'.&mt('Co-author Management Update Result').'</h3>'."\n".
6191:): &update_coauthor_managers($permission));
6192:): }
6193:): }
6194:): } elsif (($env{'form.action'} eq 'calist') && ($context eq 'author')) {
6195:): if ($permission->{'cusr'}) {
6196:): my ($role,$audom,$auname,$canview,$canedit) =
6197:): &Apache::lonviewcoauthors::get_allowable();
6198:): if (($canedit) && ($env{'form.forceedit'})) {
6199:): &Apache::lonviewcoauthors::get_editor_crumbs($brcrum,'/adm/createuser');
6200:): my $args = { 'bread_crumbs' => $brcrum };
6201:): $r->print(&Apache::loncommon::start_page('Configure co-author listing',undef,
6202:): $args).
6203:): &Apache::lonviewcoauthors::edit_settings($audom,$auname,$role,
6204:): '/adm/createuser'));
6205:): } else {
6206:): push(@{$brcrum},
6207:): {href => '/adm/createuser?action=calist',
6208:): text => 'Coauthor-viewable list',
6209:): help => 'Author_List_Coauthors'});
6210:): my $args = { 'bread_crumbs' => $brcrum };
6211:): $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6212:): $args));
6213:): my %viewsettings =
6214:): &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6215:): if ($viewsettings{'show'} eq 'none') {
6216:): $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6217:): '<p class="LC_info">'.
6218:): &mt('Listing of co-authors not enabled for this Authoring Space').
6219:): '</p>');
6220:): } else {
6221:): &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6222:): '/adm/createuser',\%viewsettings);
6223:): }
6224:): }
6225:): } else {
6226:): $r->internal_redirect('/adm/viewcoauthors');
6227:): return OK;
6228:): }
1.190 raeburn 6229: } else {
1.351 raeburn 6230: $bread_crumbs_component = 'User Management';
6231: $args = { bread_crumbs => $brcrum,
6232: bread_crumbs_component => $bread_crumbs_component};
6233: $r->print(&header(undef,$args));
1.318 raeburn 6234: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 6235: }
1.351 raeburn 6236: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 6237: return OK;
6238: }
6239:
6240: sub header {
1.351 raeburn 6241: my ($jscript,$args) = @_;
1.190 raeburn 6242: my $start_page;
1.351 raeburn 6243: if (ref($args) eq 'HASH') {
6244: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 6245: } else {
1.351 raeburn 6246: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 6247: }
6248: return $start_page;
6249: }
1.2 www 6250:
1.191 raeburn 6251: sub add_script {
6252: my ($js) = @_;
1.301 bisitz 6253: return '<script type="text/javascript">'."\n"
6254: .'// <![CDATA['."\n"
6255: .$js."\n"
6256: .'// ]]>'."\n"
6257: .'</script>'."\n";
1.191 raeburn 6258: }
6259:
1.391 raeburn 6260: sub usernamerequest_javascript {
6261: my $js = <<ENDJS;
6262:
6263: function openusernamereqdisplay(dom,uname,queue) {
6264: var url = '/adm/createuser?action=displayuserreq';
6265: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
6266: var title = 'Account_Request_Browser';
6267: var options = 'scrollbars=1,resizable=1,menubar=0';
6268: options += ',width=700,height=600';
6269: var stdeditbrowser = open(url,title,options,'1');
6270: stdeditbrowser.focus();
6271: return;
6272: }
6273:
6274: ENDJS
6275: }
6276:
6277: sub close_popup_form {
6278: my $close= &mt('Close Window');
6279: return << "END";
6280: <p><form name="displayreq" action="" method="post">
6281: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
6282: </form></p>
6283: END
6284: }
6285:
1.202 raeburn 6286: sub verify_user_display {
1.364 raeburn 6287: my ($context) = @_;
1.374 raeburn 6288: my %lt = &Apache::lonlocal::texthash (
6289: course => 'course(s): description, section(s), status',
6290: community => 'community(s): description, section(s), status',
6291: author => 'author',
6292: );
1.364 raeburn 6293: my $photos;
6294: if (($context eq 'course') && $env{'request.course.id'}) {
6295: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
6296: }
1.202 raeburn 6297: my $output = <<"END";
6298:
1.364 raeburn 6299: function hide_searching() {
6300: if (document.getElementById('searching')) {
6301: document.getElementById('searching').style.display = 'none';
6302: }
6303: return;
6304: }
6305:
1.202 raeburn 6306: function display_update() {
6307: document.studentform.action.value = 'listusers';
6308: document.studentform.phase.value = 'display';
6309: document.studentform.submit();
6310: }
6311:
1.364 raeburn 6312: function updateCols(caller) {
6313: var context = '$context';
6314: var photos = '$photos';
6315: if (caller == 'Status') {
1.374 raeburn 6316: if ((context == 'domain') &&
6317: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6318: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 6319: document.getElementById('showcolstatus').checked = false;
6320: document.getElementById('showcolstatus').disabled = 'disabled';
6321: document.getElementById('showcolstart').checked = false;
6322: document.getElementById('showcolend').checked = false;
1.374 raeburn 6323: } else {
6324: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6325: document.getElementById('showcolstatus').checked = true;
6326: document.getElementById('showcolstatus').disabled = '';
6327: document.getElementById('showcolstart').checked = true;
6328: document.getElementById('showcolend').checked = true;
6329: } else {
6330: document.getElementById('showcolstatus').checked = false;
6331: document.getElementById('showcolstatus').disabled = 'disabled';
6332: document.getElementById('showcolstart').checked = false;
6333: document.getElementById('showcolend').checked = false;
6334: }
1.406.2.20.2. (raeburn 6335:): if (context == 'author') {
6336:): if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Expired') {
6337:): document.getElementById('showcolmanager').checked = false;
6338:): document.getElementById('showcolmanager').disabled = 'disabled';
6339:): } else if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value != 'aa') {
6340:): document.getElementById('showcolmanager').checked = true;
6341:): document.getElementById('showcolmanager').disabled = '';
6342:): }
6343:): }
1.364 raeburn 6344: }
6345: }
6346: if (caller == 'output') {
6347: if (photos == 1) {
6348: if (document.getElementById('showcolphoto')) {
6349: var photoitem = document.getElementById('showcolphoto');
6350: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
6351: photoitem.checked = true;
6352: photoitem.disabled = '';
6353: } else {
6354: photoitem.checked = false;
6355: photoitem.disabled = 'disabled';
6356: }
6357: }
6358: }
6359: }
6360: if (caller == 'showrole') {
1.371 raeburn 6361: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
6362: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 6363: document.getElementById('showcolrole').checked = true;
6364: document.getElementById('showcolrole').disabled = '';
6365: } else {
6366: document.getElementById('showcolrole').checked = false;
6367: document.getElementById('showcolrole').disabled = 'disabled';
6368: }
1.374 raeburn 6369: if (context == 'domain') {
1.382 raeburn 6370: var quotausageshow = 0;
1.374 raeburn 6371: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6372: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
6373: document.getElementById('showcolstatus').checked = false;
6374: document.getElementById('showcolstatus').disabled = 'disabled';
6375: document.getElementById('showcolstart').checked = false;
6376: document.getElementById('showcolend').checked = false;
6377: } else {
6378: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6379: document.getElementById('showcolstatus').checked = true;
6380: document.getElementById('showcolstatus').disabled = '';
6381: document.getElementById('showcolstart').checked = true;
6382: document.getElementById('showcolend').checked = true;
6383: }
6384: }
6385: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
6386: document.getElementById('showcolextent').disabled = 'disabled';
6387: document.getElementById('showcolextent').checked = 'false';
6388: document.getElementById('showextent').style.display='none';
6389: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 6390: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
6391: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
6392: if (document.getElementById('showcolauthorusage')) {
6393: document.getElementById('showcolauthorusage').disabled = '';
6394: }
6395: if (document.getElementById('showcolauthorquota')) {
6396: document.getElementById('showcolauthorquota').disabled = '';
6397: }
6398: quotausageshow = 1;
6399: }
1.374 raeburn 6400: } else {
6401: document.getElementById('showextent').style.display='block';
6402: document.getElementById('showextent').style.textAlign='left';
6403: document.getElementById('showextent').style.textFace='normal';
6404: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
6405: document.getElementById('showcolextent').disabled = '';
6406: document.getElementById('showcolextent').checked = 'true';
6407: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
6408: } else {
6409: document.getElementById('showcolextent').disabled = '';
6410: document.getElementById('showcolextent').checked = 'true';
6411: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
6412: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
6413: } else {
6414: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
6415: }
6416: }
6417: }
1.382 raeburn 6418: if (quotausageshow == 0) {
6419: if (document.getElementById('showcolauthorusage')) {
6420: document.getElementById('showcolauthorusage').checked = false;
6421: document.getElementById('showcolauthorusage').disabled = 'disabled';
6422: }
6423: if (document.getElementById('showcolauthorquota')) {
6424: document.getElementById('showcolauthorquota').checked = false;
6425: document.getElementById('showcolauthorquota').disabled = 'disabled';
6426: }
6427: }
1.374 raeburn 6428: }
1.406.2.20.2. (raeburn 6429:): if (context == 'author') {
6430:): if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'aa') {
6431:): document.getElementById('showcolmanager').checked = false;
6432:): document.getElementById('showcolmanager').disabled = 'disabled';
6433:): } else if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value != 'Expired') {
6434:): document.getElementById('showcolmanager').checked = true;
6435:): document.getElementById('showcolmanager').disabled = '';
6436:): }
6437:): }
1.364 raeburn 6438: }
6439: return;
6440: }
6441:
1.202 raeburn 6442: END
6443: return $output;
6444:
6445: }
6446:
1.190 raeburn 6447: ###############################################################
6448: ###############################################################
6449: # Menu Phase One
6450: sub print_main_menu {
1.318 raeburn 6451: my ($permission,$context,$crstype) = @_;
6452: my $linkcontext = $context;
6453: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
6454: if (($context eq 'course') && ($crstype eq 'Community')) {
6455: $linkcontext = lc($crstype);
6456: $stuterm = 'Members';
6457: }
1.208 raeburn 6458: my %links = (
1.298 droeschl 6459: domain => {
6460: upload => 'Upload a File of Users',
6461: singleuser => 'Add/Modify a User',
6462: listusers => 'Manage Users',
6463: },
6464: author => {
6465: upload => 'Upload a File of Co-authors',
6466: singleuser => 'Add/Modify a Co-author',
6467: listusers => 'Manage Co-authors',
6468: },
6469: course => {
6470: upload => 'Upload a File of Course Users',
6471: singleuser => 'Add/Modify a Course User',
1.354 www 6472: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 6473: },
1.318 raeburn 6474: community => {
6475: upload => 'Upload a File of Community Users',
6476: singleuser => 'Add/Modify a Community User',
1.354 www 6477: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 6478: },
6479: );
6480: my %linktitles = (
6481: domain => {
6482: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
6483: listusers => 'Show and manage users in this domain.',
6484: },
6485: author => {
6486: singleuser => 'Add a user with a co- or assistant author role.',
6487: listusers => 'Show and manage co- or assistant authors.',
6488: },
6489: course => {
6490: singleuser => 'Add a user with a certain role to this course.',
6491: listusers => 'Show and manage users in this course.',
6492: },
6493: community => {
6494: singleuser => 'Add a user with a certain role to this community.',
6495: listusers => 'Show and manage users in this community.',
6496: },
1.298 droeschl 6497: );
1.406.2.6 raeburn 6498: if ($linkcontext eq 'domain') {
6499: unless ($permission->{'cusr'}) {
6500: $links{'domain'}{'singleuser'} = 'View a User';
6501: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
6502: }
6503: } elsif ($linkcontext eq 'course') {
6504: unless ($permission->{'cusr'}) {
6505: $links{'course'}{'singleuser'} = 'View a Course User';
6506: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
6507: $links{'course'}{'listusers'} = 'List Course Users';
6508: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
6509: }
6510: } elsif ($linkcontext eq 'community') {
6511: unless ($permission->{'cusr'}) {
6512: $links{'community'}{'singleuser'} = 'View a Community User';
6513: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
6514: $links{'community'}{'listusers'} = 'List Community Users';
6515: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
6516: }
6517: }
1.298 droeschl 6518: my @menu = ( {categorytitle => 'Single Users',
6519: items =>
6520: [
6521: {
1.318 raeburn 6522: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 6523: icon => 'edit-redo.png',
6524: #help => 'Course_Change_Privileges',
6525: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 6526: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6527: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 6528: },
6529: ]},
6530:
6531: {categorytitle => 'Multiple Users',
6532: items =>
6533: [
6534: {
1.318 raeburn 6535: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 6536: icon => 'uplusr.png',
1.298 droeschl 6537: #help => 'Course_Create_Class_List',
6538: url => '/adm/createuser?action=upload',
6539: permission => $permission->{'cusr'},
6540: linktitle => 'Upload a CSV or a text file containing users.',
6541: },
6542: {
1.318 raeburn 6543: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 6544: icon => 'mngcu.png',
1.298 droeschl 6545: #help => 'Course_View_Class_List',
6546: url => '/adm/createuser?action=listusers',
6547: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6548: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 6549: },
6550:
6551: ]},
6552:
6553: {categorytitle => 'Administration',
6554: items => [ ]},
6555: );
1.406.2.5 raeburn 6556:
1.265 mielkec 6557: if ($context eq 'domain'){
1.406.2.5 raeburn 6558: push(@{ $menu[0]->{items} }, # Single Users
6559: {
6560: linktext => 'User Access Log',
6561: icon => 'document-properties.png',
1.406.2.8 raeburn 6562: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 6563: url => '/adm/createuser?action=accesslogs',
6564: permission => $permission->{'activity'},
6565: linktitle => 'View user access log.',
6566: }
6567: );
1.298 droeschl 6568:
6569: push(@{ $menu[2]->{items} }, #Category: Administration
6570: {
6571: linktext => 'Custom Roles',
6572: icon => 'emblem-photos.png',
6573: #help => 'Course_Editing_Custom_Roles',
6574: url => '/adm/createuser?action=custom',
6575: permission => $permission->{'custom'},
6576: linktitle => 'Configure a custom role.',
6577: },
1.362 raeburn 6578: {
6579: linktext => 'Authoring Space Requests',
6580: icon => 'selfenrl-queue.png',
6581: #help => 'Domain_Role_Approvals',
6582: url => '/adm/createuser?action=processauthorreq',
6583: permission => $permission->{'cusr'},
6584: linktitle => 'Approve or reject author role requests',
6585: },
1.363 raeburn 6586: {
1.391 raeburn 6587: linktext => 'LON-CAPA Account Requests',
6588: icon => 'list-add.png',
6589: #help => 'Domain_Username_Approvals',
6590: url => '/adm/createuser?action=processusernamereq',
6591: permission => $permission->{'cusr'},
6592: linktitle => 'Approve or reject LON-CAPA account requests',
6593: },
6594: {
1.363 raeburn 6595: linktext => 'Change Log',
6596: icon => 'document-properties.png',
6597: #help => 'Course_User_Logs',
6598: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 6599: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 6600: linktitle => 'View change log.',
6601: },
1.298 droeschl 6602: );
6603:
1.265 mielkec 6604: }elsif ($context eq 'course'){
1.298 droeschl 6605: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 6606:
6607: my %linktext = (
6608: 'Course' => {
6609: single => 'Add/Modify a Student',
6610: drop => 'Drop Students',
6611: groups => 'Course Groups',
6612: },
6613: 'Community' => {
6614: single => 'Add/Modify a Member',
6615: drop => 'Drop Members',
6616: groups => 'Community Groups',
6617: },
6618: );
6619:
6620: my %linktitle = (
6621: 'Course' => {
6622: single => 'Add a user with the role of student to this course',
6623: drop => 'Remove a student from this course.',
6624: groups => 'Manage course groups',
6625: },
6626: 'Community' => {
6627: single => 'Add a user with the role of member to this community',
6628: drop => 'Remove a member from this community.',
6629: groups => 'Manage community groups',
6630: },
6631: );
6632:
1.298 droeschl 6633: push(@{ $menu[0]->{items} }, #Category: Single Users
6634: {
1.318 raeburn 6635: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 6636: #help => 'Course_Add_Student',
6637: icon => 'list-add.png',
6638: url => '/adm/createuser?action=singlestudent',
6639: permission => $permission->{'cusr'},
1.318 raeburn 6640: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 6641: },
6642: );
6643:
6644: push(@{ $menu[1]->{items} }, #Category: Multiple Users
6645: {
1.318 raeburn 6646: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 6647: icon => 'edit-undo.png',
6648: #help => 'Course_Drop_Student',
6649: url => '/adm/createuser?action=drop',
6650: permission => $permission->{'cusr'},
1.318 raeburn 6651: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6652: },
6653: );
6654: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 6655: {
6656: linktext => 'Helpdesk Access',
6657: icon => 'helpdesk-access.png',
6658: #help => 'Course_Helpdesk_Access',
6659: url => '/adm/createuser?action=helpdesk',
1.406.2.20.2. (raeburn 6660:): permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6661:): ($permission->{'view'} || $permission->{'cusr'})),
1.406.2.11 raeburn 6662: linktitle => 'Helpdesk access options',
6663: },
6664: {
1.298 droeschl 6665: linktext => 'Custom Roles',
6666: icon => 'emblem-photos.png',
6667: #help => 'Course_Editing_Custom_Roles',
6668: url => '/adm/createuser?action=custom',
6669: permission => $permission->{'custom'},
6670: linktitle => 'Configure a custom role.',
6671: },
6672: {
1.318 raeburn 6673: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6674: icon => 'grps.png',
1.298 droeschl 6675: #help => 'Course_Manage_Group',
6676: url => '/adm/coursegroups?refpage=cusr',
6677: permission => $permission->{'grp_manage'},
1.318 raeburn 6678: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6679: },
6680: {
1.328 wenzelju 6681: linktext => 'Change Log',
1.298 droeschl 6682: icon => 'document-properties.png',
6683: #help => 'Course_User_Logs',
6684: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 6685: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 6686: linktitle => 'View change log.',
6687: },
6688: );
1.277 raeburn 6689: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 6690: push(@{ $menu[2]->{items} },
1.398 raeburn 6691: {
1.298 droeschl 6692: linktext => 'Enrollment Requests',
6693: icon => 'selfenrl-queue.png',
6694: #help => 'Course_Approve_Selfenroll',
6695: url => '/adm/createuser?action=selfenrollqueue',
1.406.2.20.2. (raeburn 6696:): permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 6697: linktitle =>'Approve or reject enrollment requests.',
6698: },
6699: );
1.277 raeburn 6700: }
1.298 droeschl 6701:
1.265 mielkec 6702: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 6703: if ($crstype ne 'Community') {
6704: push(@{ $menu[2]->{items} },
6705: {
6706: linktext => 'Automated Enrollment',
6707: icon => 'roles.png',
6708: #help => 'Course_Automated_Enrollment',
6709: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 6710: && (($permission->{'cusr'}) ||
6711: ($permission->{'view'}))),
1.320 raeburn 6712: url => '/adm/populate',
6713: linktitle => 'Automated enrollment manager.',
6714: }
6715: );
6716: }
6717: push(@{ $menu[2]->{items} },
1.298 droeschl 6718: {
6719: linktext => 'User Self-Enrollment',
1.342 wenzelju 6720: icon => 'self_enroll.png',
1.298 droeschl 6721: #help => 'Course_Self_Enrollment',
6722: url => '/adm/createuser?action=selfenroll',
1.406.2.20.2. (raeburn 6723:): permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 6724: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 6725: },
6726: );
6727: }
1.363 raeburn 6728: } elsif ($context eq 'author') {
1.370 raeburn 6729: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 6730: {
6731: linktext => 'Change Log',
6732: icon => 'document-properties.png',
6733: #help => 'Course_User_Logs',
6734: url => '/adm/createuser?action=changelogs',
6735: permission => $permission->{'cusr'},
6736: linktitle => 'View change log.',
6737: },
1.406.2.20.2. (raeburn 6738:): {
6739:): linktext => 'Co-author Managers',
6740:): icon => 'camanager.png',
6741:): #help => 'Coauthor_Management',
6742:): url => '/adm/createuser?action=camanagers',
6743:): permission => $permission->{'author'},
6744:): linktitle => 'Assign/Revoke right to manage co-author roles',
6745:): },
6746:): {
6747:): linktext => 'Configure Co-author Listing',
6748:): icon => 'coauthors.png',
6749:): #help => 'Coauthor_Settings',
6750:): url => '/adm/createuser?action=calist&forceedit=1',
6751:): permission => ($permission->{'cusr'}),
6752:): linktitle => 'Set availability of coauthor-viewable user listing',
6753:): },
1.370 raeburn 6754: );
1.363 raeburn 6755: }
6756: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 6757: # { text => 'View Log-in History',
6758: # help => 'Course_User_Logins',
6759: # action => 'logins',
6760: # permission => $permission->{'cusr'},
6761: # });
1.190 raeburn 6762: }
6763:
1.189 albertel 6764: sub restore_prev_selections {
6765: my %saveable_parameters = ('srchby' => 'scalar',
6766: 'srchin' => 'scalar',
6767: 'srchtype' => 'scalar',
6768: );
6769: &Apache::loncommon::store_settings('user','user_picker',
6770: \%saveable_parameters);
6771: &Apache::loncommon::restore_settings('user','user_picker',
6772: \%saveable_parameters);
6773: }
6774:
1.237 raeburn 6775: sub print_selfenroll_menu {
1.406.2.6 raeburn 6776: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 6777: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 6778: my $formname = 'selfenroll';
1.237 raeburn 6779: my $nolink = 1;
1.398 raeburn 6780: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 6781: my $groupslist = &Apache::lonuserutils::get_groupslist();
6782: my $setsec_js =
6783: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 6784: my %alerts = &Apache::lonlocal::texthash(
6785: acto => 'Activation of self-enrollment was selected for the following domain(s)',
6786: butn => 'but no user types have been checked.',
6787: wilf => "Please uncheck 'activate' or check at least one type.",
6788: );
1.406.2.6 raeburn 6789: my $disabled;
6790: if ($readonly) {
6791: $disabled = ' disabled="disabled"';
6792: }
1.405 damieng 6793: &js_escape(\%alerts);
1.249 raeburn 6794: my $selfenroll_js = <<"ENDSCRIPT";
6795: function update_types(caller,num) {
6796: var delidx = getIndexByName('selfenroll_delete');
6797: var actidx = getIndexByName('selfenroll_activate');
6798: if (caller == 'selfenroll_all') {
6799: var selall;
6800: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6801: if (document.$formname.selfenroll_all[i].checked) {
6802: selall = document.$formname.selfenroll_all[i].value;
6803: }
6804: }
6805: if (selall == 1) {
6806: if (delidx != -1) {
6807: if (document.$formname.selfenroll_delete.length) {
6808: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
6809: document.$formname.selfenroll_delete[j].checked = true;
6810: }
6811: } else {
6812: document.$formname.elements[delidx].checked = true;
6813: }
6814: }
6815: if (actidx != -1) {
6816: if (document.$formname.selfenroll_activate.length) {
6817: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6818: document.$formname.selfenroll_activate[j].checked = false;
6819: }
6820: } else {
6821: document.$formname.elements[actidx].checked = false;
6822: }
6823: }
6824: document.$formname.selfenroll_newdom.selectedIndex = 0;
6825: }
6826: }
6827: if (caller == 'selfenroll_activate') {
6828: if (document.$formname.selfenroll_activate.length) {
6829: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6830: if (document.$formname.selfenroll_activate[j].value == num) {
6831: if (document.$formname.selfenroll_activate[j].checked) {
6832: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6833: if (document.$formname.selfenroll_all[i].value == '1') {
6834: document.$formname.selfenroll_all[i].checked = false;
6835: }
6836: if (document.$formname.selfenroll_all[i].value == '0') {
6837: document.$formname.selfenroll_all[i].checked = true;
6838: }
6839: }
6840: }
6841: }
6842: }
6843: } else {
6844: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6845: if (document.$formname.selfenroll_all[i].value == '1') {
6846: document.$formname.selfenroll_all[i].checked = false;
6847: }
6848: if (document.$formname.selfenroll_all[i].value == '0') {
6849: document.$formname.selfenroll_all[i].checked = true;
6850: }
6851: }
6852: }
6853: }
6854: if (caller == 'selfenroll_delete') {
6855: if (document.$formname.selfenroll_delete.length) {
6856: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
6857: if (document.$formname.selfenroll_delete[j].value == num) {
6858: if (document.$formname.selfenroll_delete[j].checked) {
6859: var delindex = getIndexByName('selfenroll_types_'+num);
6860: if (delindex != -1) {
6861: if (document.$formname.elements[delindex].length) {
6862: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6863: document.$formname.elements[delindex][k].checked = false;
6864: }
6865: } else {
6866: document.$formname.elements[delindex].checked = false;
6867: }
6868: }
6869: }
6870: }
6871: }
6872: } else {
6873: if (document.$formname.selfenroll_delete.checked) {
6874: var delindex = getIndexByName('selfenroll_types_'+num);
6875: if (delindex != -1) {
6876: if (document.$formname.elements[delindex].length) {
6877: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6878: document.$formname.elements[delindex][k].checked = false;
6879: }
6880: } else {
6881: document.$formname.elements[delindex].checked = false;
6882: }
6883: }
6884: }
6885: }
6886: }
6887: return;
6888: }
6889:
6890: function validate_types(form) {
6891: var needaction = new Array();
6892: var countfail = 0;
6893: var actidx = getIndexByName('selfenroll_activate');
6894: if (actidx != -1) {
6895: if (document.$formname.selfenroll_activate.length) {
6896: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6897: var num = document.$formname.selfenroll_activate[j].value;
6898: if (document.$formname.selfenroll_activate[j].checked) {
6899: countfail = check_types(num,countfail,needaction)
6900: }
6901: }
6902: } else {
6903: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 6904: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 6905: countfail = check_types(num,countfail,needaction)
6906: }
6907: }
6908: }
6909: if (countfail > 0) {
6910: var msg = "$alerts{'acto'}\\n";
6911: var loopend = needaction.length -1;
6912: if (loopend > 0) {
6913: for (var m=0; m<loopend; m++) {
6914: msg += needaction[m]+", ";
6915: }
6916: }
6917: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
6918: alert(msg);
6919: return;
6920: }
6921: setSections(form);
6922: }
6923:
6924: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 6925: var boxname = 'selfenroll_types_'+num;
6926: var typeidx = getIndexByName(boxname);
1.249 raeburn 6927: var count = 0;
6928: if (typeidx != -1) {
1.406.2.15 raeburn 6929: if (document.$formname.elements[boxname].length) {
6930: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
6931: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 6932: count ++;
6933: }
6934: }
6935: } else {
6936: if (document.$formname.elements[typeidx].checked) {
6937: count ++;
6938: }
6939: }
6940: if (count == 0) {
6941: var domidx = getIndexByName('selfenroll_dom_'+num);
6942: if (domidx != -1) {
6943: var domname = document.$formname.elements[domidx].value;
6944: needaction[countfail] = domname;
6945: countfail ++;
6946: }
6947: }
6948: }
6949: return countfail;
6950: }
6951:
1.398 raeburn 6952: function toggleNotify() {
6953: var selfenrollApproval = 0;
6954: if (document.$formname.selfenroll_approval.length) {
6955: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
6956: if (document.$formname.selfenroll_approval[i].checked) {
6957: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
6958: break;
6959: }
6960: }
6961: }
6962: if (document.getElementById('notified')) {
6963: if (selfenrollApproval == 0) {
6964: document.getElementById('notified').style.display='none';
6965: } else {
6966: document.getElementById('notified').style.display='block';
6967: }
6968: }
6969: return;
6970: }
6971:
1.249 raeburn 6972: function getIndexByName(item) {
6973: for (var i=0;i<document.$formname.elements.length;i++) {
6974: if (document.$formname.elements[i].name == item) {
6975: return i;
6976: }
6977: }
6978: return -1;
6979: }
6980: ENDSCRIPT
1.256 raeburn 6981:
1.237 raeburn 6982: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 6983: '// <![CDATA['."\n".
1.249 raeburn 6984: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 6985: '// ]]>'."\n".
1.237 raeburn 6986: '</script>'."\n".
1.256 raeburn 6987: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.406.2.20.2. (raeburn 6988:): my $visactions = &cat_visibility($cdom);
1.400 raeburn 6989: my ($cathash,%cattype);
6990: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
6991: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
6992: $cathash = $domconfig{'coursecategories'}{'cats'};
6993: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
6994: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 6995: if ($cattype{'auth'} eq '') {
6996: $cattype{'auth'} = 'std';
6997: }
6998: if ($cattype{'unauth'} eq '') {
6999: $cattype{'unauth'} = 'std';
7000: }
1.400 raeburn 7001: } else {
7002: $cathash = {};
7003: $cattype{'auth'} = 'std';
7004: $cattype{'unauth'} = 'std';
7005: }
7006: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7007: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7008: '<br />'.
7009: '<br />'.$visactions->{'take'}.'<ul>'.
7010: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7011: '</ul>');
7012: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7013: if ($currsettings->{'uniquecode'}) {
7014: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7015: } else {
7016: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7017: '<br />'.
7018: '<br />'.$visactions->{'take'}.'<ul>'.
7019: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7020: '</ul><br />');
7021: }
7022: } else {
7023: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7024: if (ref($visactions) eq 'HASH') {
7025: if ($visible) {
7026: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
7027: } else {
7028: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
7029: .$visactions->{'yous'}.
7030: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
7031: if (ref($vismsgs) eq 'ARRAY') {
7032: $output .= '<br />'.$visactions->{'make'}.'<ul>';
7033: foreach my $item (@{$vismsgs}) {
7034: $output .= '<li>'.$visactions->{$item}.'</li>';
7035: }
7036: $output .= '</ul>';
1.256 raeburn 7037: }
1.400 raeburn 7038: $output .= '</p>';
1.256 raeburn 7039: }
7040: }
7041: }
1.398 raeburn 7042: my $actionhref = '/adm/createuser';
7043: if ($context eq 'domain') {
7044: $actionhref = '/adm/modifycourse';
7045: }
1.400 raeburn 7046:
7047: my %noedit;
7048: unless ($context eq 'domain') {
7049: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7050: }
1.398 raeburn 7051: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 7052: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 7053: if (ref($row) eq 'ARRAY') {
7054: foreach my $item (@{$row}) {
7055: my $title = $item;
7056: if (ref($lt) eq 'HASH') {
7057: $title = $lt->{$item};
7058: }
1.297 bisitz 7059: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 7060: if ($item eq 'types') {
1.398 raeburn 7061: my $curr_types;
7062: if (ref($currsettings) eq 'HASH') {
7063: $curr_types = $currsettings->{'selfenroll_types'};
7064: }
1.400 raeburn 7065: if ($noedit{$item}) {
7066: if ($curr_types eq '*') {
7067: $output .= &mt('Any user in any domain');
7068: } else {
7069: my @entries = split(/;/,$curr_types);
7070: if (@entries > 0) {
7071: $output .= '<ul>';
7072: foreach my $entry (@entries) {
7073: my ($currdom,$typestr) = split(/:/,$entry);
7074: next if ($typestr eq '');
7075: my $domdesc = &Apache::lonnet::domain($currdom);
7076: my @currinsttypes = split(',',$typestr);
7077: my ($othertitle,$usertypes,$types) =
7078: &Apache::loncommon::sorted_inst_types($currdom);
7079: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7080: $usertypes->{'any'} = &mt('any user');
7081: if (keys(%{$usertypes}) > 0) {
7082: $usertypes->{'other'} = &mt('other users');
7083: }
7084: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
7085: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
7086: }
7087: }
7088: $output .= '</ul>';
7089: } else {
7090: $output .= &mt('None');
7091: }
7092: }
7093: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7094: next;
7095: }
1.241 raeburn 7096: my $showdomdesc = 1;
7097: my $includeempty = 1;
7098: my $num = 0;
7099: $output .= &Apache::loncommon::start_data_table().
7100: &Apache::loncommon::start_data_table_row()
7101: .'<td colspan="2"><span class="LC_nobreak"><label>'
7102: .&mt('Any user in any domain:')
7103: .' <input type="radio" name="selfenroll_all" value="1" ';
7104: if ($curr_types eq '*') {
7105: $output .= ' checked="checked" ';
7106: }
1.249 raeburn 7107: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 7108: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 7109: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 7110: if ($curr_types ne '*') {
7111: $output .= ' checked="checked" ';
7112: }
1.249 raeburn 7113: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 7114: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 7115: &Apache::loncommon::end_data_table_row().
7116: &Apache::loncommon::end_data_table().
7117: &mt('Or').'<br />'.
7118: &Apache::loncommon::start_data_table();
1.241 raeburn 7119: my %currdoms;
1.249 raeburn 7120: if ($curr_types eq '') {
1.241 raeburn 7121: $output .= &new_selfenroll_dom_row($cdom,'0');
7122: } elsif ($curr_types ne '*') {
7123: my @entries = split(/;/,$curr_types);
7124: if (@entries > 0) {
7125: foreach my $entry (@entries) {
7126: my ($currdom,$typestr) = split(/:/,$entry);
7127: $currdoms{$currdom} = 1;
7128: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 7129: my @currinsttypes = split(',',$typestr);
1.241 raeburn 7130: $output .= &Apache::loncommon::start_data_table_row()
7131: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
7132: .' '.$domdesc.' ('.$currdom.')'
7133: .'</b><input type="hidden" name="selfenroll_dom_'.$num
7134: .'" value="'.$currdom.'" /></span><br />'
7135: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 7136: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 7137: .&mt('Delete').'</label></span></td>';
1.249 raeburn 7138: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 7139: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 7140: .&Apache::loncommon::end_data_table_row();
7141: $num ++;
7142: }
7143: }
7144: }
1.249 raeburn 7145: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 7146: if ($curr_types eq '*') {
1.249 raeburn 7147: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 7148: } elsif ($curr_types eq '') {
1.249 raeburn 7149: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 7150: }
7151: $output .= &Apache::loncommon::start_data_table_row()
7152: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
7153: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 7154: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 7155: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
7156: .'</td>'.&Apache::loncommon::end_data_table_row()
7157: .&Apache::loncommon::end_data_table();
1.237 raeburn 7158: } elsif ($item eq 'registered') {
7159: my ($regon,$regoff);
1.398 raeburn 7160: my $registered;
7161: if (ref($currsettings) eq 'HASH') {
7162: $registered = $currsettings->{'selfenroll_registered'};
7163: }
1.400 raeburn 7164: if ($noedit{$item}) {
7165: if ($registered) {
7166: $output .= &mt('Must be registered in course');
7167: } else {
7168: $output .= &mt('No requirement');
7169: }
7170: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7171: next;
7172: }
1.398 raeburn 7173: if ($registered) {
1.237 raeburn 7174: $regon = ' checked="checked" ';
1.406.2.6 raeburn 7175: $regoff = '';
1.237 raeburn 7176: } else {
1.406.2.6 raeburn 7177: $regon = '';
1.237 raeburn 7178: $regoff = ' checked="checked" ';
7179: }
7180: $output .= '<label>'.
1.406.2.6 raeburn 7181: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 7182: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 7183: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 7184: &mt('No').'</label>';
1.237 raeburn 7185: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 7186: my ($starttime,$endtime);
7187: if (ref($currsettings) eq 'HASH') {
7188: $starttime = $currsettings->{'selfenroll_start_date'};
7189: $endtime = $currsettings->{'selfenroll_end_date'};
7190: if ($starttime eq '') {
7191: $starttime = $currsettings->{'default_enrollment_start_date'};
7192: }
7193: if ($endtime eq '') {
7194: $endtime = $currsettings->{'default_enrollment_end_date'};
7195: }
1.237 raeburn 7196: }
1.400 raeburn 7197: if ($noedit{$item}) {
7198: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7199: &Apache::lonlocal::locallocaltime($endtime));
7200: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7201: next;
7202: }
1.237 raeburn 7203: my $startform =
7204: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 7205: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7206: my $endform =
7207: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 7208: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7209: $output .= &selfenroll_date_forms($startform,$endform);
7210: } elsif ($item eq 'access_dates') {
1.398 raeburn 7211: my ($starttime,$endtime);
7212: if (ref($currsettings) eq 'HASH') {
7213: $starttime = $currsettings->{'selfenroll_start_access'};
7214: $endtime = $currsettings->{'selfenroll_end_access'};
7215: if ($starttime eq '') {
7216: $starttime = $currsettings->{'default_enrollment_start_date'};
7217: }
7218: if ($endtime eq '') {
7219: $endtime = $currsettings->{'default_enrollment_end_date'};
7220: }
1.237 raeburn 7221: }
1.400 raeburn 7222: if ($noedit{$item}) {
7223: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7224: &Apache::lonlocal::locallocaltime($endtime));
7225: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7226: next;
7227: }
1.237 raeburn 7228: my $startform =
7229: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 7230: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7231: my $endform =
7232: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 7233: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7234: $output .= &selfenroll_date_forms($startform,$endform);
7235: } elsif ($item eq 'section') {
1.398 raeburn 7236: my $currsec;
7237: if (ref($currsettings) eq 'HASH') {
7238: $currsec = $currsettings->{'selfenroll_section'};
7239: }
1.237 raeburn 7240: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
7241: my $newsecval;
7242: if ($currsec ne 'none' && $currsec ne '') {
7243: if (!defined($sections_count{$currsec})) {
7244: $newsecval = $currsec;
7245: }
7246: }
1.400 raeburn 7247: if ($noedit{$item}) {
7248: if ($currsec ne '') {
7249: $output .= $currsec;
7250: } else {
7251: $output .= &mt('No specific section');
7252: }
7253: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7254: next;
7255: }
1.237 raeburn 7256: my $sections_select =
1.406.2.6 raeburn 7257: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 7258: $output .= '<table class="LC_createuser">'."\n".
7259: '<tr class="LC_section_row">'."\n".
7260: '<td align="center">'.&mt('Existing sections')."\n".
7261: '<br />'.$sections_select.'</td><td align="center">'.
7262: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 7263: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 7264: '<input type="hidden" name="sections" value="" />'."\n".
7265: '</td></tr></table>'."\n";
1.276 raeburn 7266: } elsif ($item eq 'approval') {
1.398 raeburn 7267: my ($currnotified,$currapproval,%appchecked);
7268: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 7269: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 7270: $currnotified = $currsettings->{'selfenroll_notifylist'};
7271: $currapproval = $currsettings->{'selfenroll_approval'};
7272: }
7273: if ($currapproval !~ /^[012]$/) {
7274: $currapproval = 0;
7275: }
1.400 raeburn 7276: if ($noedit{$item}) {
7277: $output .= $selfdescs{'approval'}{$currapproval}.
7278: '<br />'.&mt('(Set by Domain Coordinator)');
7279: next;
7280: }
1.398 raeburn 7281: $appchecked{$currapproval} = ' checked="checked"';
7282: for my $i (0..2) {
7283: $output .= '<label>'.
7284: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 7285: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
7286: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 7287: }
7288: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
7289: my (@ccs,%notified);
1.322 raeburn 7290: my $ccrole = 'cc';
7291: if ($crstype eq 'Community') {
7292: $ccrole = 'co';
7293: }
7294: if ($advhash{$ccrole}) {
7295: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 7296: }
7297: if ($currnotified) {
7298: foreach my $current (split(/,/,$currnotified)) {
7299: $notified{$current} = 1;
7300: if (!grep(/^\Q$current\E$/,@ccs)) {
7301: push(@ccs,$current);
7302: }
7303: }
7304: }
7305: if (@ccs) {
1.398 raeburn 7306: my $style;
7307: unless ($currapproval) {
7308: $style = ' style="display: none;"';
7309: }
7310: $output .= '<br /><div id="notified"'.$style.'>'.
7311: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
7312: &Apache::loncommon::start_data_table().
1.276 raeburn 7313: &Apache::loncommon::start_data_table_row();
7314: my $count = 0;
7315: my $numcols = 4;
7316: foreach my $cc (sort(@ccs)) {
7317: my $notifyon;
7318: my ($ccuname,$ccudom) = split(/:/,$cc);
7319: if ($notified{$cc}) {
7320: $notifyon = ' checked="checked" ';
7321: }
7322: if ($count && !$count%$numcols) {
7323: $output .= &Apache::loncommon::end_data_table_row().
7324: &Apache::loncommon::start_data_table_row()
7325: }
7326: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 7327: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 7328: &Apache::loncommon::plainname($ccuname,$ccudom).
7329: '</label></span></td>';
1.343 raeburn 7330: $count ++;
1.276 raeburn 7331: }
7332: my $rem = $count%$numcols;
7333: if ($rem) {
7334: my $emptycols = $numcols - $rem;
7335: for (my $i=0; $i<$emptycols; $i++) {
7336: $output .= '<td> </td>';
7337: }
7338: }
7339: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 7340: &Apache::loncommon::end_data_table().
7341: '</div>';
1.276 raeburn 7342: }
7343: } elsif ($item eq 'limit') {
1.398 raeburn 7344: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
7345: if (ref($currsettings) eq 'HASH') {
7346: $currlim = $currsettings->{'selfenroll_limit'};
7347: $currcap = $currsettings->{'selfenroll_cap'};
7348: }
1.400 raeburn 7349: if ($noedit{$item}) {
7350: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
7351: if ($currlim eq 'allstudents') {
7352: $output .= &mt('Limit by total students');
7353: } elsif ($currlim eq 'selfenrolled') {
7354: $output .= &mt('Limit by total self-enrolled students');
7355: }
7356: $output .= ' '.&mt('Maximum: [_1]',$currcap).
7357: '<br />'.&mt('(Set by Domain Coordinator)');
7358: } else {
7359: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
7360: }
7361: next;
7362: }
1.276 raeburn 7363: if ($currlim eq 'allstudents') {
7364: $crslimit = ' checked="checked" ';
7365: $selflimit = ' ';
7366: $nolimit = ' ';
7367: } elsif ($currlim eq 'selfenrolled') {
7368: $crslimit = ' ';
7369: $selflimit = ' checked="checked" ';
7370: $nolimit = ' ';
7371: } else {
7372: $crslimit = ' ';
7373: $selflimit = ' ';
1.398 raeburn 7374: $nolimit = ' checked="checked" ';
1.276 raeburn 7375: }
7376: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 7377: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 7378: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 7379: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 7380: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 7381: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 7382: &mt('Limit by total self-enrolled students').
7383: '</td></tr><tr>'.
7384: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
7385: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 7386: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 7387: }
7388: $output .= &Apache::lonhtmlcommon::row_closure(1);
7389: }
7390: }
1.406.2.6 raeburn 7391: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
7392: unless ($readonly) {
7393: $output .= '<input type="button" name="selfenrollconf" value="'
7394: .&mt('Save').'" onclick="validate_types(this.form);" />';
7395: }
7396: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 7397: .'<input type="hidden" name="state" value="done" />'."\n"
7398: .$additional.'</form>';
1.237 raeburn 7399: $r->print($output);
7400: return;
7401: }
7402:
1.400 raeburn 7403: sub get_noedit_fields {
7404: my ($cdom,$cnum,$crstype,$row) = @_;
7405: my %noedit;
7406: if (ref($row) eq 'ARRAY') {
7407: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
7408: 'internal.selfenrollmgrdc',
7409: 'internal.selfenrollmgrcc'],$cdom,$cnum);
7410: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
7411: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
7412: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
7413: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
7414: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7415: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
7416:
7417: foreach my $item (@{$row}) {
7418: next if ($specific_managebycc{$item});
7419: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
7420: $noedit{$item} = 1;
7421: }
7422: }
7423: }
7424: return %noedit;
7425: }
7426:
7427: sub visible_in_stdcat {
7428: my ($cdom,$cnum,$domconf) = @_;
7429: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
7430: unless (ref($domconf) eq 'HASH') {
7431: return ($visible,$cansetvis,\@vismsgs);
7432: }
7433: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7434: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 7435: $settable{'togglecats'} = 1;
7436: }
1.400 raeburn 7437: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 7438: $settable{'categorize'} = 1;
7439: }
1.400 raeburn 7440: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7441: }
1.260 raeburn 7442: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 7443: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
7444: } elsif ($settable{'togglecats'}) {
7445: $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 7446: } elsif ($settable{'categorize'}) {
1.256 raeburn 7447: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
7448: } else {
7449: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
7450: }
7451:
7452: my %currsettings =
7453: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
7454: $cdom,$cnum);
1.400 raeburn 7455: $visible = 0;
1.256 raeburn 7456: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 7457: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7458: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7459: if (ref($cathash) eq 'HASH') {
7460: if ($cathash->{'instcode::0'} eq '') {
7461: push(@vismsgs,'dc_addinst');
7462: } else {
7463: $visible = 1;
7464: }
7465: } else {
7466: $visible = 1;
7467: }
7468: } else {
7469: $visible = 1;
7470: }
7471: } else {
7472: if (ref($cathash) eq 'HASH') {
7473: if ($cathash->{'instcode::0'} ne '') {
7474: push(@vismsgs,'dc_instcode');
7475: }
7476: } else {
7477: push(@vismsgs,'dc_instcode');
7478: }
7479: }
7480: if ($currsettings{'categories'} ne '') {
7481: my $cathash;
1.400 raeburn 7482: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7483: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7484: if (ref($cathash) eq 'HASH') {
7485: if (keys(%{$cathash}) == 0) {
7486: push(@vismsgs,'dc_catalog');
7487: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
7488: push(@vismsgs,'dc_categories');
7489: } else {
7490: my @currcategories = split('&',$currsettings{'categories'});
7491: my $matched = 0;
7492: foreach my $cat (@currcategories) {
7493: if ($cathash->{$cat} ne '') {
7494: $visible = 1;
7495: $matched = 1;
7496: last;
7497: }
7498: }
7499: if (!$matched) {
1.260 raeburn 7500: if ($settable{'categorize'}) {
1.256 raeburn 7501: push(@vismsgs,'chgcat');
7502: } else {
7503: push(@vismsgs,'dc_chgcat');
7504: }
7505: }
7506: }
7507: }
7508: }
7509: } else {
7510: if (ref($cathash) eq 'HASH') {
7511: if ((keys(%{$cathash}) > 1) ||
7512: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 7513: if ($settable{'categorize'}) {
1.256 raeburn 7514: push(@vismsgs,'addcat');
7515: } else {
7516: push(@vismsgs,'dc_addcat');
7517: }
7518: }
7519: }
7520: }
7521: if ($currsettings{'hidefromcat'} eq 'yes') {
7522: $visible = 0;
7523: if ($settable{'togglecats'}) {
7524: unshift(@vismsgs,'unhide');
7525: } else {
7526: unshift(@vismsgs,'dc_unhide')
7527: }
7528: }
1.400 raeburn 7529: return ($visible,$cansetvis,\@vismsgs);
7530: }
7531:
7532: sub cat_visibility {
1.406.2.20.2. (raeburn 7533:): my ($cdom) = @_;
1.400 raeburn 7534: my %visactions = &Apache::lonlocal::texthash(
7535: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
7536: 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.',
7537: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
7538: none => 'Display of a course catalog is disabled for this domain.',
7539: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
7540: 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.',
7541: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
7542: take => 'Take the following action to ensure the course appears in the Catalog:',
7543: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
7544: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
7545: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.406.2.20.2. (raeburn 7546:): dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 7547: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
7548: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
7549: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
7550: 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',
7551: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
7552: );
1.406.2.20.2. (raeburn 7553:): if ($env{'request.role'} eq "dc./$cdom/") {
7554:): $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
7555:): $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.','»');
7556:): $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
7557:): $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)".','»');
7558:): $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).','»');
7559:): $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.','»');
7560:): $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.','»');
7561:): $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.','»');
7562:): $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.','»');
7563:): }
1.400 raeburn 7564: $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>"');
7565: $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>"');
7566: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
7567: return \%visactions;
1.256 raeburn 7568: }
7569:
1.241 raeburn 7570: sub new_selfenroll_dom_row {
7571: my ($newdom,$num) = @_;
7572: my $domdesc = &Apache::lonnet::domain($newdom);
7573: my $output;
7574: if ($domdesc ne '') {
7575: $output .= &Apache::loncommon::start_data_table_row()
7576: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
7577: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 7578: .'" value="'.$newdom.'" /></span><br />'
7579: .'<span class="LC_nobreak"><label><input type="checkbox" '
7580: .'name="selfenroll_activate" value="'.$num.'" '
7581: .'onchange="javascript:update_types('
7582: ."'selfenroll_activate','$num'".');" />'
7583: .&mt('Activate').'</label></span></td>';
1.241 raeburn 7584: my @currinsttypes;
7585: $output .= '<td>'.&mt('User types:').'<br />'
7586: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
7587: .&Apache::loncommon::end_data_table_row();
7588: }
7589: return $output;
7590: }
7591:
7592: sub selfenroll_inst_types {
1.406.2.6 raeburn 7593: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 7594: my $output;
7595: my $numinrow = 4;
7596: my $count = 0;
7597: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 7598: my $othervalue = 'any';
1.406.2.6 raeburn 7599: my $disabled;
7600: if ($readonly) {
7601: $disabled = ' disabled="disabled"';
7602: }
1.241 raeburn 7603: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 7604: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 7605: $othervalue = 'other';
7606: }
1.241 raeburn 7607: $output .= '<table><tr>';
7608: foreach my $type (@{$types}) {
7609: if (($count > 0) && ($count%$numinrow == 0)) {
7610: $output .= '</tr><tr>';
7611: }
7612: if (defined($usertypes->{$type})) {
1.257 raeburn 7613: my $esc_type = &escape($type);
1.241 raeburn 7614: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 7615: $esc_type.'" ';
1.241 raeburn 7616: if (ref($currinsttypes) eq 'ARRAY') {
7617: if (@{$currinsttypes} > 0) {
1.249 raeburn 7618: if (grep(/^any$/,@{$currinsttypes})) {
7619: $output .= 'checked="checked"';
1.257 raeburn 7620: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 7621: $output .= 'checked="checked"';
7622: }
1.249 raeburn 7623: } else {
7624: $output .= 'checked="checked"';
1.241 raeburn 7625: }
7626: }
1.406.2.6 raeburn 7627: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 7628: }
7629: $count ++;
7630: }
7631: if (($count > 0) && ($count%$numinrow == 0)) {
7632: $output .= '</tr><tr>';
7633: }
1.249 raeburn 7634: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 7635: if (ref($currinsttypes) eq 'ARRAY') {
7636: if (@{$currinsttypes} > 0) {
1.249 raeburn 7637: if (grep(/^any$/,@{$currinsttypes})) {
7638: $output .= ' checked="checked"';
7639: } elsif ($othervalue eq 'other') {
7640: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
7641: $output .= ' checked="checked"';
7642: }
1.241 raeburn 7643: }
1.249 raeburn 7644: } else {
7645: $output .= ' checked="checked"';
1.241 raeburn 7646: }
1.249 raeburn 7647: } else {
7648: $output .= ' checked="checked"';
1.241 raeburn 7649: }
1.406.2.6 raeburn 7650: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 7651: }
7652: return $output;
7653: }
7654:
1.237 raeburn 7655: sub selfenroll_date_forms {
7656: my ($startform,$endform) = @_;
7657: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 7658: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 7659: 'LC_oddrow_value')."\n".
7660: $startform."\n".
7661: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 7662: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 7663: 'LC_oddrow_value')."\n".
7664: $endform."\n".
7665: &Apache::lonhtmlcommon::row_closure(1).
7666: &Apache::lonhtmlcommon::end_pick_box();
7667: return $output;
7668: }
7669:
1.239 raeburn 7670: sub print_userchangelogs_display {
1.406.2.5 raeburn 7671: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 7672: my $formname = 'rolelog';
1.406.2.6 raeburn 7673: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 7674: if ($context eq 'domain') {
7675: $domain = $env{'request.role.domain'};
7676: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
7677: } else {
7678: if ($context eq 'course') {
7679: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
7680: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
7681: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 7682: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 7683: my %saveable_parameters = ('show' => 'scalar',);
7684: &Apache::loncommon::store_course_settings('roles_log',
7685: \%saveable_parameters);
7686: &Apache::loncommon::restore_course_settings('roles_log',
7687: \%saveable_parameters);
7688: } elsif ($context eq 'author') {
1.406.2.20.2. (raeburn 7689:): $domain = $env{'user.domain'};
1.363 raeburn 7690: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
7691: $username = $env{'user.name'};
1.406.2.20.2. (raeburn 7692:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
7693:): ($domain,$username) = ($1,$2);
1.363 raeburn 7694: } else {
7695: undef($domain);
7696: }
7697: }
7698: if ($domain ne '' && $username ne '') {
7699: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
7700: }
7701: }
1.239 raeburn 7702: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
7703:
1.406.2.5 raeburn 7704: my $helpitem;
7705: if ($context eq 'course') {
7706: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 7707: } elsif ($context eq 'domain') {
7708: $helpitem = 'Domain_Role_Logs';
7709: } elsif ($context eq 'author') {
7710: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 7711: }
7712: push (@{$brcrum},
7713: {href => '/adm/createuser?action=changelogs',
7714: text => 'User Management Logs',
7715: help => $helpitem});
7716: my $bread_crumbs_component = 'User Changes';
7717: my $args = { bread_crumbs => $brcrum,
7718: bread_crumbs_component => $bread_crumbs_component};
7719:
7720: # Create navigation javascript
7721: my $jsnav = &userlogdisplay_js($formname);
7722:
7723: my $jscript = (<<ENDSCRIPT);
7724: <script type="text/javascript">
7725: // <![CDATA[
7726: $jsnav
7727: // ]]>
7728: </script>
7729: ENDSCRIPT
7730:
7731: # print page header
7732: $r->print(&header($jscript,$args));
7733:
1.239 raeburn 7734: # set defaults
7735: my $now = time();
7736: my $defstart = $now - (7*24*3600); #7 days ago
7737: my %defaults = (
7738: page => '1',
7739: show => '10',
7740: role => 'any',
7741: chgcontext => 'any',
7742: rolelog_start_date => $defstart,
7743: rolelog_end_date => $now,
7744: );
7745: my $more_records = 0;
7746:
7747: # set current
7748: my %curr;
7749: foreach my $item ('show','page','role','chgcontext') {
7750: $curr{$item} = $env{'form.'.$item};
7751: }
7752: my ($startdate,$enddate) =
7753: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
7754: $curr{'rolelog_start_date'} = $startdate;
7755: $curr{'rolelog_end_date'} = $enddate;
7756: foreach my $key (keys(%defaults)) {
7757: if ($curr{$key} eq '') {
7758: $curr{$key} = $defaults{$key};
7759: }
7760: }
1.248 raeburn 7761: my (%whodunit,%changed,$version);
7762: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 7763: my ($minshown,$maxshown);
1.255 raeburn 7764: $minshown = 1;
1.239 raeburn 7765: my $count = 0;
1.406.2.5 raeburn 7766: if ($curr{'show'} =~ /\D/) {
7767: $curr{'page'} = 1;
7768: } else {
1.239 raeburn 7769: $maxshown = $curr{'page'} * $curr{'show'};
7770: if ($curr{'page'} > 1) {
7771: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7772: }
7773: }
1.301 bisitz 7774:
1.327 raeburn 7775: # Form Header
7776: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 7777: &role_display_filter($context,$formname,$domain,$username,\%curr,
7778: $version,$crstype));
1.327 raeburn 7779:
7780: my $showntableheader = 0;
7781:
7782: # Table Header
7783: my $tableheader =
7784: &Apache::loncommon::start_data_table_header_row()
7785: .'<th> </th>'
7786: .'<th>'.&mt('When').'</th>'
7787: .'<th>'.&mt('Who made the change').'</th>'
7788: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 7789: .'<th>'.&mt('Role').'</th>';
7790:
7791: if ($context eq 'course') {
7792: $tableheader .= '<th>'.&mt('Section').'</th>';
7793: }
7794: $tableheader .=
7795: '<th>'.&mt('Context').'</th>'
1.327 raeburn 7796: .'<th>'.&mt('Start').'</th>'
7797: .'<th>'.&mt('End').'</th>'
7798: .&Apache::loncommon::end_data_table_header_row();
7799:
7800: # Display user change log data
1.239 raeburn 7801: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
7802: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
7803: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 7804: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 7805: if ($count >= $curr{'page'} * $curr{'show'}) {
7806: $more_records = 1;
7807: last;
7808: }
7809: }
7810: if ($curr{'role'} ne 'any') {
7811: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
7812: }
7813: if ($curr{'chgcontext'} ne 'any') {
7814: if ($curr{'chgcontext'} eq 'selfenroll') {
7815: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
7816: } else {
7817: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
7818: }
7819: }
1.406.2.6 raeburn 7820: if (($context eq 'course') && ($viewablesec ne '')) {
7821: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
7822: }
1.239 raeburn 7823: $count ++;
7824: next if ($count < $minshown);
1.327 raeburn 7825: unless ($showntableheader) {
1.406.2.5 raeburn 7826: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 7827: .$tableheader);
7828: $r->rflush();
7829: $showntableheader = 1;
7830: }
1.239 raeburn 7831: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
7832: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
7833: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
7834: }
7835: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
7836: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
7837: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
7838: }
7839: my $sec = $roleslog{$id}{'logentry'}{'section'};
7840: if ($sec eq '') {
7841: $sec = &mt('None');
7842: }
7843: my ($rolestart,$roleend);
7844: if ($roleslog{$id}{'delflag'}) {
7845: $rolestart = &mt('deleted');
7846: $roleend = &mt('deleted');
7847: } else {
7848: $rolestart = $roleslog{$id}{'logentry'}{'start'};
7849: $roleend = $roleslog{$id}{'logentry'}{'end'};
7850: if ($rolestart eq '' || $rolestart == 0) {
7851: $rolestart = &mt('No start date');
7852: } else {
7853: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
7854: }
7855: if ($roleend eq '' || $roleend == 0) {
7856: $roleend = &mt('No end date');
7857: } else {
7858: $roleend = &Apache::lonlocal::locallocaltime($roleend);
7859: }
7860: }
7861: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
7862: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
7863: $chgcontext = 'selfenroll';
7864: }
1.363 raeburn 7865: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 7866: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
7867: $chgcontext = $lt{$chgcontext};
7868: }
1.327 raeburn 7869: $r->print(
1.301 bisitz 7870: &Apache::loncommon::start_data_table_row()
7871: .'<td>'.$count.'</td>'
7872: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
7873: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
7874: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 7875: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
7876: if ($context eq 'course') {
7877: $r->print('<td>'.$sec.'</td>');
7878: }
7879: $r->print(
7880: '<td>'.$chgcontext.'</td>'
1.301 bisitz 7881: .'<td>'.$rolestart.'</td>'
7882: .'<td>'.$roleend.'</td>'
1.327 raeburn 7883: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 7884: }
7885:
1.327 raeburn 7886: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 7887: $r->print(&Apache::loncommon::end_data_table().
7888: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 7889: } else { # No content displayed above
1.301 bisitz 7890: $r->print('<p class="LC_info">'
7891: .&mt('There are no records to display.')
7892: .'</p>'
7893: );
1.239 raeburn 7894: }
1.301 bisitz 7895:
1.327 raeburn 7896: # Form Footer
7897: $r->print(
7898: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7899: .'<input type="hidden" name="action" value="changelogs" />'
7900: .'</form>');
7901: return;
7902: }
1.301 bisitz 7903:
1.406.2.5 raeburn 7904: sub print_useraccesslogs_display {
7905: my ($r,$uname,$udom,$permission,$brcrum) = @_;
7906: my $formname = 'accesslog';
7907: my $form = 'document.accesslog';
7908:
7909: # set breadcrumbs
1.406.2.7 raeburn 7910: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 7911: my $prevphasestr;
7912: if ($env{'form.popup'}) {
7913: $brcrum = [];
7914: } else {
7915: push (@{$brcrum},
7916: {href => "javascript:backPage($form)",
7917: text => $breadcrumb_text{'search'}});
7918: my @prevphases;
7919: if ($env{'form.prevphases'}) {
7920: @prevphases = split(/,/,$env{'form.prevphases'});
7921: $prevphasestr = $env{'form.prevphases'};
7922: }
7923: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
7924: push(@{$brcrum},
7925: {href => "javascript:backPage($form,'get_user_info','select')",
7926: text => $breadcrumb_text{'userpicked'}});
7927: if ($env{'form.phase'} eq 'userpicked') {
7928: $prevphasestr = 'userpicked';
7929: }
1.406.2.5 raeburn 7930: }
7931: }
7932: push(@{$brcrum},
7933: {href => '/adm/createuser?action=accesslogs',
7934: text => 'User access logs',
1.406.2.8 raeburn 7935: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 7936: my $bread_crumbs_component = 'User Access Logs';
7937: my $args = { bread_crumbs => $brcrum,
7938: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 7939: if ($env{'form.popup'}) {
7940: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 7941: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 7942: }
1.406.2.5 raeburn 7943:
7944: # set javascript
7945: my ($jsback,$elements) = &crumb_utilities();
7946: my $jsnav = &userlogdisplay_js($formname);
7947:
7948: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 7949: <script type="text/javascript">
1.301 bisitz 7950: // <![CDATA[
1.406.2.5 raeburn 7951:
7952: $jsback
7953: $jsnav
7954:
7955: // ]]>
7956: </script>
7957:
7958: ENDSCRIPT
7959:
7960: # print page header
7961: $r->print(&header($jscript,$args));
7962:
7963: # early out unless log data can be displayed.
7964: unless ($permission->{'activity'}) {
7965: $r->print('<p class="LC_warning">'
7966: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 7967: .'</p>');
7968: if ($env{'form.popup'}) {
7969: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
7970: } else {
7971: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7972: }
1.406.2.5 raeburn 7973: return;
7974: }
7975:
7976: unless ($udom eq $env{'request.role.domain'}) {
7977: $r->print('<p class="LC_warning">'
7978: .&mt("User's domain must match role's domain")
7979: .'</p>'
7980: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7981: return;
7982: }
7983:
7984: if (($uname eq '') || ($udom eq '')) {
7985: $r->print('<p class="LC_warning">'
7986: .&mt('Invalid username or domain')
7987: .'</p>'
7988: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
7989: return;
7990: }
7991:
1.406.2.13 raeburn 7992: if (&Apache::lonnet::privileged($uname,$udom,
7993: [$env{'request.role.domain'}],['dc','su'])) {
7994: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
7995: [$env{'request.role.domain'}],['dc','su'])) {
7996: $r->print('<p class="LC_warning">'
7997: .&mt('You need to be a privileged user to display user access logs for [_1]',
7998: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
7999: $uname,$udom))
8000: .'</p>');
8001: if ($env{'form.popup'}) {
8002: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8003: } else {
8004: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8005: }
8006: return;
8007: }
8008: }
8009:
1.406.2.5 raeburn 8010: # set defaults
8011: my $now = time();
8012: my $defstart = $now - (7*24*3600);
8013: my %defaults = (
8014: page => '1',
8015: show => '10',
8016: activity => 'any',
8017: accesslog_start_date => $defstart,
8018: accesslog_end_date => $now,
8019: );
8020: my $more_records = 0;
8021:
8022: # set current
8023: my %curr;
8024: foreach my $item ('show','page','activity') {
8025: $curr{$item} = $env{'form.'.$item};
8026: }
8027: my ($startdate,$enddate) =
8028: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
8029: $curr{'accesslog_start_date'} = $startdate;
8030: $curr{'accesslog_end_date'} = $enddate;
8031: foreach my $key (keys(%defaults)) {
8032: if ($curr{$key} eq '') {
8033: $curr{$key} = $defaults{$key};
8034: }
8035: }
8036: my ($minshown,$maxshown);
8037: $minshown = 1;
8038: my $count = 0;
8039: if ($curr{'show'} =~ /\D/) {
8040: $curr{'page'} = 1;
8041: } else {
8042: $maxshown = $curr{'page'} * $curr{'show'};
8043: if ($curr{'page'} > 1) {
8044: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8045: }
8046: }
8047:
8048: # form header
8049: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
8050: &activity_display_filter($formname,\%curr));
8051:
8052: my $showntableheader = 0;
8053: my ($nav_script,$nav_links);
8054:
8055: # table header
1.406.2.18 raeburn 8056: my $heading = '<h3>'.
1.406.2.12 raeburn 8057: &mt('User access logs for: [_1]',
1.406.2.18 raeburn 8058: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
8059: my $tableheader = $heading
1.406.2.12 raeburn 8060: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 8061: .'<th> </th>'
8062: .'<th>'.&mt('When').'</th>'
8063: .'<th>'.&mt('HostID').'</th>'
8064: .'<th>'.&mt('Event').'</th>'
8065: .'<th>'.&mt('Other data').'</th>'
8066: .&Apache::loncommon::end_data_table_header_row();
8067:
8068: my %filters=(
8069: start => $curr{'accesslog_start_date'},
8070: end => $curr{'accesslog_end_date'},
8071: action => $curr{'activity'},
8072: );
8073:
8074: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
8075: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
8076: my (%courses,%missing);
8077: my @results = split(/\&/,$reply);
8078: foreach my $item (reverse(@results)) {
8079: my ($timestamp,$host,$event) = split(/:/,$item);
8080: next unless ($event =~ /^(Log|Role)/);
8081: if ($curr{'show'} !~ /\D/) {
8082: if ($count >= $curr{'page'} * $curr{'show'}) {
8083: $more_records = 1;
8084: last;
8085: }
8086: }
8087: $count ++;
8088: next if ($count < $minshown);
8089: unless ($showntableheader) {
8090: $r->print($nav_script
8091: .&Apache::loncommon::start_data_table()
8092: .$tableheader);
8093: $r->rflush();
8094: $showntableheader = 1;
8095: }
1.406.2.6 raeburn 8096: my ($shown,$extra);
1.406.2.13 raeburn 8097: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 8098: if ($event eq 'Role') {
8099: my ($rolecode,$extent) = split(/\./,$data,2);
8100: next if ($extent eq '');
8101: my ($crstype,$desc,$info);
1.406.2.6 raeburn 8102: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
8103: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 8104: my $cid = $cdom.'_'.$cnum;
8105: if (exists($courses{$cid})) {
8106: $crstype = $courses{$cid}{'type'};
8107: $desc = $courses{$cid}{'description'};
8108: } elsif ($missing{$cid}) {
8109: $crstype = 'Course';
8110: $desc = 'Course/Community';
8111: } else {
8112: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
8113: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
8114: $courses{$cid} = $crsinfo{$cid};
8115: $crstype = $crsinfo{$cid}{'type'};
8116: $desc = $crsinfo{$cid}{'description'};
8117: } else {
8118: $missing{$cid} = 1;
8119: }
8120: }
8121: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 8122: if ($sec ne '') {
8123: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
8124: }
1.406.2.5 raeburn 8125: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
8126: my ($dom,$name) = ($1,$2);
8127: if ($rolecode eq 'au') {
8128: $extra = '';
8129: } elsif ($rolecode =~ /^(ca|aa)$/) {
8130: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
8131: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
8132: $extra = &mt('Domain: [_1]',$dom);
8133: }
8134: }
8135: my $rolename;
8136: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
8137: my $role = $3;
8138: my $owner = "($2:$1)";
8139: if ($2 eq $1.'-domainconfig') {
8140: $owner = '(ad hoc)';
8141: }
8142: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
8143: } else {
8144: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
8145: }
8146: $shown = &mt('Role selection: [_1]',$rolename);
8147: } else {
8148: $shown = &mt($event);
1.406.2.13 raeburn 8149: if ($data =~ /^webdav/) {
8150: my ($path,$clientip) = split(/\s+/,$data,2);
8151: $path =~ s/^webdav//;
8152: if ($clientip ne '') {
8153: $extra = &mt('Client IP address: [_1]',$clientip);
8154: }
8155: if ($path ne '') {
8156: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
8157: }
8158: } elsif ($data ne '') {
8159: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 8160: }
8161: }
8162: $r->print(
8163: &Apache::loncommon::start_data_table_row()
8164: .'<td>'.$count.'</td>'
8165: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
8166: .'<td>'.$host.'</td>'
8167: .'<td>'.$shown.'</td>'
8168: .'<td>'.$extra.'</td>'
8169: .&Apache::loncommon::end_data_table_row()."\n");
8170: }
8171: }
8172:
8173: if ($showntableheader) { # Table footer, if content displayed above
8174: $r->print(&Apache::loncommon::end_data_table().
8175: &userlogdisplay_navlinks(\%curr,$more_records));
8176: } else { # No content displayed above
1.406.2.18 raeburn 8177: $r->print($heading.'<p class="LC_info">'
1.406.2.5 raeburn 8178: .&mt('There are no records to display.')
8179: .'</p>');
8180: }
8181:
1.406.2.8 raeburn 8182: if ($env{'form.popup'} == 1) {
8183: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
8184: }
8185:
1.406.2.5 raeburn 8186: # Form Footer
8187: $r->print(
8188: '<input type="hidden" name="currstate" value="" />'
8189: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
8190: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
8191: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8192: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
8193: .'<input type="hidden" name="phase" value="activity" />'
8194: .'<input type="hidden" name="action" value="accesslogs" />'
8195: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
8196: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
8197: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
8198: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
8199: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
8200: .'</form>');
8201: return;
8202: }
8203:
8204: sub earlyout_accesslog_form {
8205: my ($formname,$prevphasestr,$udom) = @_;
8206: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
8207: return <<"END";
8208: <form action="/adm/createuser" method="post" name="$formname">
8209: <input type="hidden" name="currstate" value="" />
8210: <input type="hidden" name="prevphases" value="$prevphasestr" />
8211: <input type="hidden" name="phase" value="activity" />
8212: <input type="hidden" name="action" value="accesslogs" />
8213: <input type="hidden" name="srchdomain" value="$udom" />
8214: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
8215: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
8216: <input type="hidden" name="srchterm" value="$srchterm" />
8217: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
8218: </form>
8219: END
8220: }
8221:
8222: sub activity_display_filter {
8223: my ($formname,$curr) = @_;
8224: my $nolink = 1;
8225: my $output = '<table><tr><td valign="top">'.
8226: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
8227: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
8228: (&mt('all'),5,10,20,50,100,1000,10000)).
8229: '</td><td> </td>';
8230: my $startform =
8231: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
8232: $curr->{'accesslog_start_date'},undef,
8233: undef,undef,undef,undef,undef,undef,$nolink);
8234: my $endform =
8235: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
8236: $curr->{'accesslog_end_date'},undef,
8237: undef,undef,undef,undef,undef,undef,$nolink);
8238: my %lt = &Apache::lonlocal::texthash (
8239: activity => 'Activity',
8240: Role => 'Role selection',
8241: log => 'Log-in or Logout',
8242: );
8243: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
8244: '<table><tr><td>'.&mt('After:').
8245: '</td><td>'.$startform.'</td></tr>'.
8246: '<tr><td>'.&mt('Before:').'</td>'.
8247: '<td>'.$endform.'</td></tr></table>'.
8248: '</td>'.
8249: '<td> </td>'.
8250: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
8251: '<select name="activity"><option value="any"';
8252: if ($curr->{'activity'} eq 'any') {
8253: $output .= ' selected="selected"';
8254: }
8255: $output .= '>'.&mt('Any').'</option>'."\n";
8256: foreach my $activity ('Role','log') {
8257: my $selstr = '';
8258: if ($activity eq $curr->{'activity'}) {
8259: $selstr = ' selected="selected"';
8260: }
8261: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
8262: }
8263: $output .= '</select></td>'.
8264: '</tr></table>';
8265: # Update Display button
8266: $output .= '<p>'
8267: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 8268: .'</p><hr />';
1.406.2.5 raeburn 8269: return $output;
8270: }
8271:
8272: sub userlogdisplay_js {
8273: my ($formname) = @_;
8274: return <<"ENDSCRIPT";
8275:
1.239 raeburn 8276: function chgPage(caller) {
8277: if (caller == 'previous') {
8278: document.$formname.page.value --;
8279: }
8280: if (caller == 'next') {
8281: document.$formname.page.value ++;
8282: }
1.327 raeburn 8283: document.$formname.submit();
1.239 raeburn 8284: return;
8285: }
8286: ENDSCRIPT
1.406.2.5 raeburn 8287: }
8288:
8289: sub userlogdisplay_navlinks {
8290: my ($curr,$more_records) = @_;
8291: return unless(ref($curr) eq 'HASH');
8292: # Navigation Buttons
8293: my $nav_links = '<p>';
8294: if (($curr->{'page'} > 1) || ($more_records)) {
8295: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
8296: $nav_links .= '<input type="button"'
8297: .' onclick="javascript:chgPage('."'previous'".');"'
8298: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
8299: .'" /> ';
8300: }
8301: if ($more_records) {
8302: $nav_links .= '<input type="button"'
8303: .' onclick="javascript:chgPage('."'next'".');"'
8304: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
8305: .'" />';
1.301 bisitz 8306: }
8307: }
1.406.2.5 raeburn 8308: $nav_links .= '</p>';
8309: return $nav_links;
1.239 raeburn 8310: }
8311:
8312: sub role_display_filter {
1.363 raeburn 8313: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
8314: my $lctype;
8315: if ($context eq 'course') {
8316: $lctype = lc($crstype);
8317: }
1.239 raeburn 8318: my $nolink = 1;
8319: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 8320: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 8321: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
8322: (&mt('all'),5,10,20,50,100,1000,10000)).
8323: '</td><td> </td>';
8324: my $startform =
8325: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
8326: $curr->{'rolelog_start_date'},undef,
8327: undef,undef,undef,undef,undef,undef,$nolink);
8328: my $endform =
8329: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
8330: $curr->{'rolelog_end_date'},undef,
8331: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 8332: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 8333: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
8334: '<table><tr><td>'.&mt('After:').
8335: '</td><td>'.$startform.'</td></tr>'.
8336: '<tr><td>'.&mt('Before:').'</td>'.
8337: '<td>'.$endform.'</td></tr></table>'.
8338: '</td>'.
8339: '<td> </td>'.
1.239 raeburn 8340: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
8341: '<select name="role"><option value="any"';
8342: if ($curr->{'role'} eq 'any') {
8343: $output .= ' selected="selected"';
8344: }
8345: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 8346: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 8347: foreach my $role (@roles) {
8348: my $plrole;
8349: if ($role eq 'cr') {
8350: $plrole = &mt('Custom Role');
8351: } else {
1.318 raeburn 8352: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 8353: }
8354: my $selstr = '';
8355: if ($role eq $curr->{'role'}) {
8356: $selstr = ' selected="selected"';
8357: }
8358: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
8359: }
1.301 bisitz 8360: $output .= '</select></td>'.
8361: '<td> </td>'.
8362: '<td valign="top"><b>'.
1.239 raeburn 8363: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 8364: my @posscontexts;
8365: if ($context eq 'course') {
1.406.2.20 raeburn 8366: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 8367: } elsif ($context eq 'domain') {
8368: @posscontexts = ('any','domain','requestauthor','domconfig','server');
8369: } else {
1.406.2.20.2. (raeburn 8370:): @posscontexts = ('any','author','coauthor','domain');
1.406.2.20 raeburn 8371: }
1.363 raeburn 8372: foreach my $chgtype (@posscontexts) {
1.239 raeburn 8373: my $selstr = '';
8374: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 8375: $selstr = ' selected="selected"';
1.239 raeburn 8376: }
1.363 raeburn 8377: if ($context eq 'course') {
1.376 raeburn 8378: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 8379: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
8380: }
1.239 raeburn 8381: }
8382: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 8383: }
1.303 bisitz 8384: $output .= '</select></td>'
8385: .'</tr></table>';
8386:
8387: # Update Display button
8388: $output .= '<p>'
8389: .'<input type="submit" value="'.&mt('Update Display').'" />'
8390: .'</p>';
8391:
8392: # Server version info
1.363 raeburn 8393: my $needsrev = '2.11.0';
8394: if ($context eq 'course') {
8395: $needsrev = '2.7.0';
8396: }
8397:
1.303 bisitz 8398: $output .= '<p class="LC_info">'
8399: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 8400: ,$needsrev);
1.248 raeburn 8401: if ($version) {
1.303 bisitz 8402: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
8403: }
8404: $output .= '</p><hr />';
1.239 raeburn 8405: return $output;
8406: }
8407:
8408: sub rolechg_contexts {
1.363 raeburn 8409: my ($context,$crstype) = @_;
8410: my %lt;
8411: if ($context eq 'course') {
8412: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 8413: any => 'Any',
1.376 raeburn 8414: automated => 'Automated Enrollment',
1.406.2.20 raeburn 8415: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 8416: updatenow => 'Roster Update',
8417: createcourse => 'Course Creation',
8418: course => 'User Management in course',
8419: domain => 'User Management in domain',
1.313 raeburn 8420: selfenroll => 'Self-enrolled',
1.318 raeburn 8421: requestcourses => 'Course Request',
1.239 raeburn 8422: );
1.363 raeburn 8423: if ($crstype eq 'Community') {
8424: $lt{'createcourse'} = &mt('Community Creation');
8425: $lt{'course'} = &mt('User Management in community');
8426: $lt{'requestcourses'} = &mt('Community Request');
8427: }
8428: } elsif ($context eq 'domain') {
8429: %lt = &Apache::lonlocal::texthash (
8430: any => 'Any',
8431: domain => 'User Management in domain',
8432: requestauthor => 'Authoring Request',
8433: server => 'Command line script (DC role)',
8434: domconfig => 'Self-enrolled',
8435: );
8436: } else {
8437: %lt = &Apache::lonlocal::texthash (
8438: any => 'Any',
8439: domain => 'User Management in domain',
8440: author => 'User Management by author',
1.406.2.20.2. (raeburn 8441:): coauthor => 'User Management by coauthor',
1.363 raeburn 8442: );
8443: }
1.239 raeburn 8444: return %lt;
8445: }
8446:
1.406.2.10 raeburn 8447: sub print_helpdeskaccess_display {
8448: my ($r,$permission,$brcrum) = @_;
8449: my $formname = 'helpdeskaccess';
8450: my $helpitem = 'Course_Helpdesk_Access';
8451: push (@{$brcrum},
8452: {href => '/adm/createuser?action=helpdesk',
8453: text => 'Helpdesk Access',
8454: help => $helpitem});
8455: my $bread_crumbs_component = 'Helpdesk Staff Access';
8456: my $args = { bread_crumbs => $brcrum,
8457: bread_crumbs_component => $bread_crumbs_component};
8458:
8459: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8460: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8461: my $confname = $cdom.'-domainconfig';
8462: my $crstype = &Apache::loncommon::course_type();
8463:
1.406.2.12 raeburn 8464: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 8465: my ($numstatustypes,@jsarray);
8466: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8467: if (ref($types) eq 'ARRAY') {
8468: if (@{$types} > 0) {
8469: $numstatustypes = scalar(@{$types});
8470: push(@accesstypes,'status');
8471: @jsarray = ('bystatus');
8472: }
8473: }
8474: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 8475: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8476: if (keys(%domhelpdesk)) {
8477: push(@accesstypes,('inc','exc'));
8478: push(@jsarray,('notinc','notexc'));
8479: }
8480: push(@jsarray,'privs');
8481: my $hiddenstr = join("','",@jsarray);
8482: my $rolestr = join("','",sort(keys(%customroles)));
8483:
8484: my $jscript;
8485: my (%settings,%overridden);
8486: if (keys(%customroles)) {
8487: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8488: $types,\%customroles,\%settings,\%overridden);
8489: my %jsfull=();
8490: my %jslevels= (
8491: course => {},
8492: domain => {},
8493: system => {},
8494: );
8495: my %jslevelscurrent=(
8496: course => {},
8497: domain => {},
8498: system => {},
8499: );
8500: my (%privs,%jsprivs);
8501: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
8502: foreach my $priv (keys(%jsfull)) {
8503: if ($jslevels{'course'}{$priv}) {
8504: $jsprivs{$priv} = 1;
8505: }
8506: }
8507: my (%elements,%stored);
8508: foreach my $role (keys(%customroles)) {
8509: $elements{$role.'_access'} = 'radio';
8510: $elements{$role.'_incrs'} = 'radio';
8511: if ($numstatustypes) {
8512: $elements{$role.'_status'} = 'checkbox';
8513: }
8514: if (keys(%domhelpdesk) > 0) {
8515: $elements{$role.'_staff_inc'} = 'checkbox';
8516: $elements{$role.'_staff_exc'} = 'checkbox';
8517: }
8518: $elements{$role.'_override'} = 'checkbox';
8519: if (ref($settings{$role}) eq 'HASH') {
8520: if ($settings{$role}{'access'} ne '') {
8521: my $curraccess = $settings{$role}{'access'};
8522: $stored{$role.'_access'} = $curraccess;
8523: $stored{$role.'_incrs'} = 1;
8524: if ($curraccess eq 'status') {
8525: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
8526: $stored{$role.'_status'} = $settings{$role}{'status'};
8527: }
8528: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8529: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
8530: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
8531: }
8532: }
8533: } else {
8534: $stored{$role.'_incrs'} = 0;
8535: }
8536: $stored{$role.'_override'} = [];
8537: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
8538: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
8539: foreach my $priv (@{$settings{$role}{'off'}}) {
8540: push(@{$stored{$role.'_override'}},$priv);
8541: }
8542: }
8543: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
8544: foreach my $priv (@{$settings{$role}{'on'}}) {
8545: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
8546: push(@{$stored{$role.'_override'}},$priv);
8547: }
8548: }
8549: }
8550: }
8551: } else {
8552: $stored{$role.'_incrs'} = 0;
8553: }
8554: }
8555: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
8556: }
8557:
8558: my $js = <<"ENDJS";
8559: <script type="text/javascript">
8560: // <![CDATA[
8561: $jscript;
8562:
8563: function switchRoleTab(caller,role) {
8564: if (document.getElementById(role+'_maindiv')) {
8565: if (caller.id != 'LC_current_minitab') {
8566: if (document.getElementById('LC_current_minitab')) {
8567: document.getElementById('LC_current_minitab').id=null;
8568: }
8569: var roledivs = Array('$rolestr');
8570: if (roledivs.length > 0) {
8571: for (var i=0; i<roledivs.length; i++) {
8572: if (document.getElementById(roledivs[i]+'_maindiv')) {
8573: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
8574: }
8575: }
8576: }
8577: caller.id = 'LC_current_minitab';
8578: document.getElementById(role+'_maindiv').style.display='block';
8579: }
8580: }
8581: return false;
8582: }
8583:
8584: function helpdeskAccess(role) {
8585: var curraccess = null;
8586: if (document.$formname.elements[role+'_access'].length) {
8587: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
8588: if (document.$formname.elements[role+'_access'][i].checked) {
8589: curraccess = document.$formname.elements[role+'_access'][i].value;
8590: }
8591: }
8592: }
8593: var shown = Array();
8594: var hidden = Array();
8595: if (curraccess == 'none') {
8596: hidden = Array ('$hiddenstr');
8597: } else {
8598: if (curraccess == 'status') {
8599: shown = Array ('bystatus','privs');
8600: hidden = Array ('notinc','notexc');
8601: } else {
8602: if (curraccess == 'exc') {
8603: shown = Array ('notexc','privs');
8604: hidden = Array ('notinc','bystatus');
8605: }
8606: if (curraccess == 'inc') {
8607: shown = Array ('notinc','privs');
8608: hidden = Array ('notexc','bystatus');
8609: }
8610: if (curraccess == 'all') {
8611: shown = Array ('privs');
8612: hidden = Array ('notinc','notexc','bystatus');
8613: }
8614: }
8615: }
8616: if (hidden.length > 0) {
8617: for (var i=0; i<hidden.length; i++) {
8618: if (document.getElementById(role+'_'+hidden[i])) {
8619: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
8620: }
8621: }
8622: }
8623: if (shown.length > 0) {
8624: for (var i=0; i<shown.length; i++) {
8625: if (document.getElementById(role+'_'+shown[i])) {
8626: if (shown[i] == 'privs') {
8627: document.getElementById(role+'_'+shown[i]).style.display = 'block';
8628: } else {
8629: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
8630: }
8631: }
8632: }
8633: }
8634: return;
8635: }
8636:
8637: function toggleAccess(role) {
8638: if ((document.getElementById(role+'_setincrs')) &&
8639: (document.getElementById(role+'_setindom'))) {
8640: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
8641: if (document.$formname.elements[role+'_incrs'][i].checked) {
8642: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
8643: document.getElementById(role+'_setindom').style.display = 'none';
8644: document.getElementById(role+'_setincrs').style.display = 'block';
8645: } else {
8646: document.getElementById(role+'_setincrs').style.display = 'none';
8647: document.getElementById(role+'_setindom').style.display = 'block';
8648: }
8649: break;
8650: }
8651: }
8652: }
8653: return;
8654: }
8655:
8656: // ]]>
8657: </script>
8658: ENDJS
8659:
8660: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
8661:
8662: # print page header
8663: $r->print(&header($js,$args));
8664: # print form header
8665: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
8666:
8667: if (keys(%customroles)) {
8668: my %lt = &Apache::lonlocal::texthash(
8669: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
8670: 'rou' => 'Role usage',
8671: 'whi' => 'Which helpdesk personnel may use this role?',
8672: 'udd' => 'Use domain default',
1.406.2.12 raeburn 8673: 'all' => 'All with domain helpdesk or helpdesk assistant role',
8674: 'dh' => 'All with domain helpdesk role',
8675: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 8676: 'none' => 'None',
8677: 'status' => 'Determined based on institutional status',
8678: 'inc' => 'Include all, but exclude specific personnel',
8679: 'exc' => 'Exclude all, but include specific personnel',
8680: 'hel' => 'Helpdesk',
8681: 'rpr' => 'Role privileges',
8682: );
8683: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
8684: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8685: my (%domcurrent,%ordered,%description,%domusage,$disabled);
8686: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8687: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8688: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8689: }
8690: }
8691: my $count = 0;
8692: foreach my $role (sort(keys(%customroles))) {
8693: my ($order,$desc,$access_in_dom);
8694: if (ref($domcurrent{$role}) eq 'HASH') {
8695: $order = $domcurrent{$role}{'order'};
8696: $desc = $domcurrent{$role}{'desc'};
8697: $access_in_dom = $domcurrent{$role}{'access'};
8698: }
8699: if ($order eq '') {
8700: $order = $count;
8701: }
8702: $ordered{$order} = $role;
8703: if ($desc ne '') {
8704: $description{$role} = $desc;
8705: } else {
8706: $description{$role}= $role;
8707: }
8708: $count++;
8709: }
8710: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8711: my @roles_by_num = ();
8712: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8713: push(@roles_by_num,$ordered{$item});
8714: }
8715: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
8716: if ($permission->{'owner'}) {
8717: $r->print('<br />'.$lt{'aco'}.'</p><p>');
8718: $r->print('<input type="hidden" name="state" value="process" />'.
8719: '<input type="submit" value="'.&mt('Save changes').'" />');
8720: } else {
8721: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
8722: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
8723: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
8724: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
8725: }
8726: $disabled = ' disabled="disabled"';
8727: }
8728: $r->print('</p>');
8729:
8730: $r->print('<div id="LC_minitab_header"><ul>');
8731: my $count = 0;
8732: my %visibility;
8733: foreach my $role (@roles_by_num) {
8734: my $id;
8735: if ($count == 0) {
8736: $id=' id="LC_current_minitab"';
8737: $visibility{$role} = ' style="display:block"';
8738: } else {
8739: $visibility{$role} = ' style="display:none"';
8740: }
8741: $count ++;
8742: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
8743: }
8744: $r->print('</ul></div>');
8745:
8746: foreach my $role (@roles_by_num) {
8747: my %usecheck = (
8748: all => ' checked="checked"',
8749: );
8750: my %displaydiv = (
8751: status => 'none',
8752: inc => 'none',
8753: exc => 'none',
8754: priv => 'block',
8755: );
8756: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
8757: if (ref($settings{$role}) eq 'HASH') {
8758: if ($settings{$role}{'access'} ne '') {
8759: $indomvis = ' style="display:none"';
8760: $incrsvis = ' style="display:block"';
8761: $incrscheck = ' checked="checked"';
8762: if ($settings{$role}{'access'} ne 'all') {
8763: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
8764: delete($usecheck{'all'});
8765: if ($settings{$role}{'access'} eq 'status') {
8766: my $access = 'status';
8767: $displaydiv{$access} = 'inline';
8768: if (ref($settings{$role}{$access}) eq 'ARRAY') {
8769: $selected{$access} = $settings{$role}{$access};
8770: }
8771: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
8772: my $access = $1;
8773: $displaydiv{$access} = 'inline';
8774: if (ref($settings{$role}{$access}) eq 'ARRAY') {
8775: $selected{$access} = $settings{$role}{$access};
8776: }
8777: } elsif ($settings{$role}{'access'} eq 'none') {
8778: $displaydiv{'priv'} = 'none';
8779: }
8780: }
8781: } else {
8782: $indomcheck = ' checked="checked"';
8783: $indomvis = ' style="display:block"';
8784: $incrsvis = ' style="display:none"';
8785: }
8786: } else {
8787: $indomcheck = ' checked="checked"';
8788: $indomvis = ' style="display:block"';
8789: $incrsvis = ' style="display:none"';
8790: }
8791: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
8792: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
8793: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
8794: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
8795: &mt('Set here in [_1]',lc($crstype)).'</label>'.
8796: '<span>'.(' 'x2).
8797: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
8798: $lt{'udd'}.'</label><span></p>'.
8799: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
8800: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
8801: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
8802: foreach my $access (@accesstypes) {
8803: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
8804: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
8805: if ($access eq 'status') {
8806: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
8807: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
8808: $othertitle,$usertypes,$types,$disabled).
8809: '</div>');
8810: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
8811: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
8812: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
8813: \%domhelpdesk,$disabled).
8814: '</div>');
8815: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
8816: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
8817: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
8818: \%domhelpdesk,$disabled).
8819: '</div>');
8820: }
8821: $r->print('</p>');
8822: }
8823: $r->print('</div></fieldset>');
8824: my %full=();
8825: my %levels= (
8826: course => {},
8827: domain => {},
8828: system => {},
8829: );
8830: my %levelscurrent=(
8831: course => {},
8832: domain => {},
8833: system => {},
8834: );
8835: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8836: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
8837: '<legend>'.$lt{'rpr'}.'</legend>'.
8838: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
8839: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
8840: }
8841: if ($permission->{'owner'}) {
8842: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
8843: }
8844: } else {
8845: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
8846: }
8847: # Form Footer
8848: $r->print('<input type="hidden" name="action" value="helpdesk" />'
8849: .'</form>');
8850: return;
8851: }
8852:
8853: sub domain_adhoc_access {
8854: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
8855: my %domusage;
8856: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
8857: foreach my $role (keys(%{$roles})) {
8858: if (ref($domcurrent->{$role}) eq 'HASH') {
8859: my $access = $domcurrent->{$role}{'access'};
8860: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
8861: $access = 'all';
1.406.2.12 raeburn 8862: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
8863: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8864: } elsif ($access eq 'status') {
8865: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
8866: my @shown;
8867: foreach my $type (@{$domcurrent->{$role}{$access}}) {
8868: unless ($type eq 'default') {
8869: if ($usertypes->{$type}) {
8870: push(@shown,$usertypes->{$type});
8871: }
8872: }
8873: }
8874: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
8875: push(@shown,$othertitle);
8876: }
8877: if (@shown) {
8878: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 8879: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
8880: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 8881: } else {
8882: $domusage{$role} = &mt('No one in the domain');
8883: }
8884: }
8885: } elsif ($access eq 'inc') {
8886: my @dominc = ();
8887: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
8888: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
8889: my ($uname,$udom) = split(/:/,$user);
8890: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8891: }
8892: my $showninc = join(', ',@dominc);
8893: if ($showninc ne '') {
1.406.2.12 raeburn 8894: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
8895: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 8896: } else {
1.406.2.12 raeburn 8897: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8898: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8899: }
8900: }
8901: } elsif ($access eq 'exc') {
8902: my @domexc = ();
8903: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
8904: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
8905: my ($uname,$udom) = split(/:/,$user);
8906: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8907: }
8908: }
8909: my $shownexc = join(', ',@domexc);
8910: if ($shownexc ne '') {
1.406.2.12 raeburn 8911: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
8912: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 8913: } else {
8914: $domusage{$role} = &mt('No one in the domain');
8915: }
8916: } elsif ($access eq 'none') {
8917: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 8918: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 8919: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 8920: } elsif ($access eq 'da') {
8921: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
8922: } elsif ($access eq 'all') {
8923: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8924: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8925: }
8926: } else {
1.406.2.12 raeburn 8927: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8928: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8929: }
8930: }
8931: return %domusage;
8932: }
8933:
8934: sub get_domain_customroles {
8935: my ($cdom,$confname) = @_;
8936: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
8937: my %customroles;
8938: foreach my $key (keys(%existing)) {
8939: if ($key=~/^rolesdef\_(\w+)$/) {
8940: my $rolename = $1;
8941: my %privs;
8942: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
8943: $customroles{$rolename} = \%privs;
8944: }
8945: }
8946: return %customroles;
8947: }
8948:
8949: sub role_priv_table {
8950: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
8951: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
8952: (ref($levelscurrent) eq 'HASH'));
8953: my %lt=&Apache::lonlocal::texthash (
8954: 'crl' => 'Course Level Privilege',
8955: 'def' => 'Domain Defaults',
8956: 'ove' => 'Override in Course',
8957: 'ine' => 'In effect',
8958: 'dis' => 'Disabled',
8959: 'ena' => 'Enabled',
8960: );
8961: if ($crstype eq 'Community') {
8962: $lt{'ove'} = 'Override in Community',
8963: }
8964: my @status = ('Disabled','Enabled');
8965: my (%on,%off);
8966: if (ref($overridden) eq 'HASH') {
8967: if (ref($overridden->{'on'}) eq 'ARRAY') {
8968: map { $on{$_} = 1; } (@{$overridden->{'on'}});
8969: }
8970: if (ref($overridden->{'off'}) eq 'ARRAY') {
8971: map { $off{$_} = 1; } (@{$overridden->{'off'}});
8972: }
8973: }
8974: my $output=&Apache::loncommon::start_data_table().
8975: &Apache::loncommon::start_data_table_header_row().
8976: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
8977: '</th><th>'.$lt{'ine'}.'</th>'.
8978: &Apache::loncommon::end_data_table_header_row();
8979: foreach my $priv (sort(keys(%{$full}))) {
8980: next unless ($levels->{'course'}{$priv});
8981: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
8982: my ($default,$ineffect);
8983: if ($levelscurrent->{'course'}{$priv}) {
8984: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
8985: $ineffect = $default;
8986: }
8987: my ($customstatus,$checked);
8988: $output .= &Apache::loncommon::start_data_table_row().
8989: '<td>'.$privtext.'</td>'.
8990: '<td>'.$default.'</td><td>';
8991: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
8992: if ($permission->{'owner'}) {
8993: $checked = ' checked="checked"';
8994: }
8995: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
8996: $ineffect = $customstatus;
8997: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
8998: if ($permission->{'owner'}) {
8999: $checked = ' checked="checked"';
9000: }
9001: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9002: $ineffect = $customstatus;
9003: }
9004: if ($permission->{'owner'}) {
9005: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
9006: } else {
9007: $output .= $customstatus;
9008: }
9009: $output .= '</td><td>'.$ineffect.'</td>'.
9010: &Apache::loncommon::end_data_table_row();
9011: }
9012: $output .= &Apache::loncommon::end_data_table();
9013: return $output;
9014: }
9015:
9016: sub get_adhocrole_settings {
9017: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
9018: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
9019: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
9020: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
9021: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
9022: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
9023: $settings->{$role}{'access'} = $curraccess;
9024: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
9025: my @status = split(/,/,$rest);
9026: my @currstatus;
9027: foreach my $type (@status) {
9028: if ($type eq 'default') {
9029: push(@currstatus,$type);
9030: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9031: push(@currstatus,$type);
9032: }
9033: }
9034: if (@currstatus) {
9035: $settings->{$role}{$curraccess} = \@currstatus;
9036: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
9037: my @personnel = split(/,/,$rest);
9038: $settings->{$role}{$curraccess} = \@personnel;
9039: }
9040: }
9041: }
9042: }
9043: foreach my $role (keys(%{$customroles})) {
9044: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
9045: my %currentprivs;
9046: if (ref($customroles->{$role}) eq 'HASH') {
9047: if (exists($customroles->{$role}{'course'})) {
9048: my %full=();
9049: my %levels= (
9050: course => {},
9051: domain => {},
9052: system => {},
9053: );
9054: my %levelscurrent=(
9055: course => {},
9056: domain => {},
9057: system => {},
9058: );
9059: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
9060: %currentprivs = %{$levelscurrent{'course'}};
9061: }
9062: }
9063: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
9064: next if ($item eq '');
9065: my ($rule,$rest) = split(/=/,$item);
9066: next unless (($rule eq 'off') || ($rule eq 'on'));
9067: foreach my $priv (split(/:/,$rest)) {
9068: if ($priv ne '') {
9069: if ($rule eq 'off') {
9070: push(@{$overridden->{$role}{'off'}},$priv);
9071: if ($currentprivs{$priv}) {
9072: push(@{$settings->{$role}{'off'}},$priv);
9073: }
9074: } else {
9075: push(@{$overridden->{$role}{'on'}},$priv);
9076: unless ($currentprivs{$priv}) {
9077: push(@{$settings->{$role}{'on'}},$priv);
9078: }
9079: }
9080: }
9081: }
9082: }
9083: }
9084: }
9085: return;
9086: }
9087:
9088: sub update_helpdeskaccess {
9089: my ($r,$permission,$brcrum) = @_;
9090: my $helpitem = 'Course_Helpdesk_Access';
9091: push (@{$brcrum},
9092: {href => '/adm/createuser?action=helpdesk',
9093: text => 'Helpdesk Access',
9094: help => $helpitem},
9095: {href => '/adm/createuser?action=helpdesk',
9096: text => 'Result',
9097: help => $helpitem}
9098: );
9099: my $bread_crumbs_component = 'Helpdesk Staff Access';
9100: my $args = { bread_crumbs => $brcrum,
9101: bread_crumbs_component => $bread_crumbs_component};
9102:
9103: # print page header
9104: $r->print(&header('',$args));
9105: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
9106: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
9107: return;
9108: }
1.406.2.12 raeburn 9109: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 9110: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9111: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9112: my $confname = $cdom.'-domainconfig';
9113: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
9114: my $crstype = &Apache::loncommon::course_type();
9115: my %customroles = &get_domain_customroles($cdom,$confname);
9116: my (%settings,%overridden);
9117: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
9118: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 9119: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 9120: my (%changed,%storehash,@todelete);
9121:
9122: if (keys(%customroles)) {
9123: my (%newsettings,@incrs);
9124: foreach my $role (keys(%customroles)) {
9125: $newsettings{$role} = {
9126: access => '',
9127: status => '',
9128: exc => '',
9129: inc => '',
9130: on => '',
9131: off => '',
9132: };
9133: my %current;
9134: if (ref($settings{$role}) eq 'HASH') {
9135: %current = %{$settings{$role}};
9136: }
9137: if (ref($overridden{$role}) eq 'HASH') {
9138: $current{'overridden'} = $overridden{$role};
9139: }
9140: if ($env{'form.'.$role.'_incrs'}) {
9141: my $access = $env{'form.'.$role.'_access'};
9142: if (grep(/^\Q$access\E$/,@accesstypes)) {
9143: push(@incrs,$role);
9144: unless ($current{'access'} eq $access) {
9145: $changed{$role}{'access'} = 1;
9146: $storehash{'internal.adhoc.'.$role} = $access;
9147: }
9148: if ($access eq 'status') {
9149: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
9150: my @stored;
9151: my @shownstatus;
9152: if (ref($types) eq 'ARRAY') {
9153: foreach my $type (sort(@statuses)) {
9154: if ($type eq 'default') {
9155: push(@stored,$type);
9156: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9157: push(@stored,$type);
9158: push(@shownstatus,$usertypes->{$type});
9159: }
9160: }
9161: if (grep(/^default$/,@statuses)) {
9162: push(@shownstatus,$othertitle);
9163: }
9164: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9165: }
9166: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
9167: if (ref($current{'status'}) eq 'ARRAY') {
9168: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
9169: if (@diffs) {
9170: $changed{$role}{'status'} = 1;
9171: }
9172: } elsif (@stored) {
9173: $changed{$role}{'status'} = 1;
9174: }
9175: } elsif (($access eq 'inc') || ($access eq 'exc')) {
9176: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
9177: my @newspecstaff;
9178: my @stored;
9179: my @currstaff;
9180: foreach my $person (sort(@personnel)) {
9181: if ($domhelpdesk{$person}) {
9182: push(@stored,$person);
9183: }
9184: }
9185: if (ref($current{$access}) eq 'ARRAY') {
9186: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
9187: if (@diffs) {
9188: $changed{$role}{$access} = 1;
9189: }
9190: } elsif (@stored) {
9191: $changed{$role}{$access} = 1;
9192: }
9193: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9194: foreach my $person (@stored) {
9195: my ($uname,$udom) = split(/:/,$person);
9196: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
9197: }
9198: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
9199: }
9200: $newsettings{$role}{'access'} = $access;
9201: }
9202: } else {
9203: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
9204: $changed{$role}{'access'} = 1;
9205: $newsettings{$role} = {};
9206: push(@todelete,'internal.adhoc.'.$role);
9207: }
9208: }
9209: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
9210: if (ref($current{'overridden'}) eq 'HASH') {
9211: push(@todelete,'internal.adhocpriv.'.$role);
9212: }
9213: } else {
9214: my %full=();
9215: my %levels= (
9216: course => {},
9217: domain => {},
9218: system => {},
9219: );
9220: my %levelscurrent=(
9221: course => {},
9222: domain => {},
9223: system => {},
9224: );
9225: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9226: my (@updatedon,@updatedoff,@override);
9227: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
9228: if (@override) {
9229: foreach my $priv (sort(keys(%full))) {
9230: next unless ($levels{'course'}{$priv});
9231: if (grep(/^\Q$priv\E$/,@override)) {
9232: if ($levelscurrent{'course'}{$priv}) {
9233: push(@updatedoff,$priv);
9234: } else {
9235: push(@updatedon,$priv);
9236: }
9237: }
9238: }
9239: }
9240: if (@updatedon) {
9241: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
9242: }
9243: if (@updatedoff) {
9244: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
9245: }
9246: if (ref($current{'overridden'}) eq 'HASH') {
9247: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
9248: if (@updatedon) {
9249: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
9250: if (@diffs) {
9251: $changed{$role}{'on'} = 1;
9252: }
9253: } else {
9254: $changed{$role}{'on'} = 1;
9255: }
9256: } elsif (@updatedon) {
9257: $changed{$role}{'on'} = 1;
9258: }
9259: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
9260: if (@updatedoff) {
9261: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
9262: if (@diffs) {
9263: $changed{$role}{'off'} = 1;
9264: }
9265: } else {
9266: $changed{$role}{'off'} = 1;
9267: }
9268: } elsif (@updatedoff) {
9269: $changed{$role}{'off'} = 1;
9270: }
9271: } else {
9272: if (@updatedon) {
9273: $changed{$role}{'on'} = 1;
9274: }
9275: if (@updatedoff) {
9276: $changed{$role}{'off'} = 1;
9277: }
9278: }
9279: if (ref($changed{$role}) eq 'HASH') {
9280: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
9281: my $newpriv;
9282: if (@updatedon) {
9283: $newpriv = 'on='.join(':',@updatedon);
9284: }
9285: if (@updatedoff) {
9286: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
9287: }
9288: if ($newpriv eq '') {
9289: push(@todelete,'internal.adhocpriv.'.$role);
9290: } else {
9291: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
9292: }
9293: }
9294: }
9295: }
9296: }
9297: if (@incrs) {
9298: $storehash{'internal.adhocaccess'} = join(',',@incrs);
9299: } elsif (@todelete) {
9300: push(@todelete,'internal.adhocaccess');
9301: }
9302: if (keys(%changed)) {
9303: my ($putres,$delres);
9304: if (keys(%storehash)) {
9305: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
9306: my %newenvhash;
9307: foreach my $key (keys(%storehash)) {
9308: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
9309: }
9310: &Apache::lonnet::appenv(\%newenvhash);
9311: }
9312: if (@todelete) {
9313: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
9314: foreach my $key (@todelete) {
9315: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
9316: }
9317: }
9318: if (($putres eq 'ok') || ($delres eq 'ok')) {
9319: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9320: my (%domcurrent,%ordered,%description,%domusage);
9321: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9322: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9323: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9324: }
9325: }
9326: my $count = 0;
9327: foreach my $role (sort(keys(%customroles))) {
9328: my ($order,$desc);
9329: if (ref($domcurrent{$role}) eq 'HASH') {
9330: $order = $domcurrent{$role}{'order'};
9331: $desc = $domcurrent{$role}{'desc'};
9332: }
9333: if ($order eq '') {
9334: $order = $count;
9335: }
9336: $ordered{$order} = $role;
9337: if ($desc ne '') {
9338: $description{$role} = $desc;
9339: } else {
9340: $description{$role}= $role;
9341: }
9342: $count++;
9343: }
9344: my @roles_by_num = ();
9345: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9346: push(@roles_by_num,$ordered{$item});
9347: }
9348: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
9349: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
9350: $r->print('<ul>');
9351: foreach my $role (@roles_by_num) {
9352: next unless (ref($changed{$role}) eq 'HASH');
9353: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
9354: '<ul>');
9355: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
9356: $r->print('<li>');
9357: if ($env{'form.'.$role.'_incrs'}) {
9358: if ($newsettings{$role}{'access'} eq 'all') {
9359: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 9360: } elsif ($newsettings{$role}{'access'} eq 'dh') {
9361: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9362: &Apache::lonnet::plaintext('dh')));
9363: } elsif ($newsettings{$role}{'access'} eq 'da') {
9364: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9365: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 9366: } elsif ($newsettings{$role}{'access'} eq 'none') {
9367: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9368: } elsif ($newsettings{$role}{'access'} eq 'status') {
9369: if ($newsettings{$role}{'status'}) {
9370: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
9371: if (split(/,/,$rest) > 1) {
9372: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
9373: $newsettings{$role}{'status'}));
9374: } else {
9375: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
9376: $newsettings{$role}{'status'}));
9377: }
9378: } else {
9379: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9380: }
9381: } elsif ($newsettings{$role}{'access'} eq 'exc') {
9382: if ($newsettings{$role}{'exc'}) {
9383: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
9384: } else {
9385: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9386: }
9387: } elsif ($newsettings{$role}{'access'} eq 'inc') {
9388: if ($newsettings{$role}{'inc'}) {
9389: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
9390: } else {
9391: $r->print(&mt('All helpdesk staff may use this role.'));
9392: }
9393: }
9394: } else {
9395: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
9396: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
9397: }
9398: $r->print('</li>');
9399: }
9400: unless ($newsettings{$role}{'access'} eq 'none') {
9401: if ($changed{$role}{'off'}) {
9402: if ($newsettings{$role}{'off'}) {
9403: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
9404: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
9405: } else {
9406: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
9407: }
9408: }
9409: if ($changed{$role}{'on'}) {
9410: if ($newsettings{$role}{'on'}) {
9411: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
9412: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
9413: } else {
9414: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
9415: }
9416: }
9417: }
9418: $r->print('</ul></li>');
9419: }
9420: $r->print('</ul>');
9421: }
9422: } else {
9423: $r->print(&mt('No changes made to helpdesk access settings.'));
9424: }
9425: }
9426: return;
9427: }
9428:
1.27 matthew 9429: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 9430: sub user_search_result {
1.221 raeburn 9431: my ($context,$srch) = @_;
1.160 raeburn 9432: my %allhomes;
9433: my %inst_matches;
9434: my %srch_results;
1.181 raeburn 9435: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 9436: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 9437: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 9438: $response = &mt('Invalid search.');
9439: }
9440: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
9441: $response = &mt('Invalid search.');
9442: }
1.177 raeburn 9443: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 9444: $response = &mt('Invalid search.');
9445: }
9446: if ($srch->{'srchterm'} eq '') {
9447: $response = &mt('You must enter a search term.');
9448: }
1.183 raeburn 9449: if ($srch->{'srchterm'} =~ /^\s+$/) {
9450: $response = &mt('Your search term must contain more than just spaces.');
9451: }
1.160 raeburn 9452: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
9453: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 9454: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 9455: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
9456: }
9457: }
9458: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
9459: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 9460: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 9461: my $unamecheck = $srch->{'srchterm'};
9462: if ($srch->{'srchtype'} eq 'contains') {
9463: if ($unamecheck !~ /^\w/) {
9464: $unamecheck = 'a'.$unamecheck;
9465: }
9466: }
9467: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 9468: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
9469: }
1.160 raeburn 9470: }
9471: }
1.180 raeburn 9472: if ($response ne '') {
1.406.2.4 raeburn 9473: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 9474: }
1.160 raeburn 9475: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 9476: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 9477: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 9478: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 9479: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 9480: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 9481: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 9482: }
1.406.2.5 raeburn 9483: $response .= '<br />';
1.406.2.3 raeburn 9484: }
9485: } else {
9486: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
9487: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 9488: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 9489: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 9490: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 9491: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 9492: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 9493: }
1.406.2.5 raeburn 9494: $response .= '<br />';
1.406.2.3 raeburn 9495: }
1.160 raeburn 9496: }
9497: }
9498: if ($response ne '') {
1.180 raeburn 9499: return ($currstate,$response);
1.160 raeburn 9500: }
9501: if ($srch->{'srchby'} eq 'uname') {
9502: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
9503: if ($env{'form.forcenew'}) {
9504: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
9505: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9506: if ($uhome eq 'no_host') {
9507: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 9508: my $showdom = &display_domain_info($env{'request.role.domain'});
9509: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 9510: } else {
1.179 raeburn 9511: $currstate = 'modify';
1.160 raeburn 9512: }
9513: } else {
1.179 raeburn 9514: $currstate = 'modify';
1.160 raeburn 9515: }
9516: } else {
9517: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 9518: if ($srch->{'srchtype'} eq 'exact') {
9519: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9520: if ($uhome eq 'no_host') {
1.179 raeburn 9521: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9522: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9523: } else {
1.179 raeburn 9524: $currstate = 'modify';
1.406.2.5 raeburn 9525: if ($env{'form.action'} eq 'accesslogs') {
9526: $currstate = 'activity';
9527: }
1.310 raeburn 9528: my $uname = $srch->{'srchterm'};
9529: my $udom = $srch->{'srchdomain'};
9530: $srch_results{$uname.':'.$udom} =
9531: { &Apache::lonnet::get('environment',
9532: ['firstname',
9533: 'lastname',
9534: 'permanentemail'],
9535: $udom,$uname)
9536: };
1.162 raeburn 9537: }
9538: } else {
9539: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9540: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9541: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9542: }
9543: } else {
1.167 albertel 9544: my $courseusers = &get_courseusers();
1.162 raeburn 9545: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 9546: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 9547: $currstate = 'modify';
1.162 raeburn 9548: } else {
1.179 raeburn 9549: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9550: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9551: }
1.160 raeburn 9552: } else {
1.167 albertel 9553: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 9554: my ($cuname,$cudomain) = split(/:/,$user);
9555: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 9556: my $matched = 0;
9557: if ($srch->{'srchtype'} eq 'begins') {
9558: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
9559: $matched = 1;
9560: }
9561: } else {
9562: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
9563: $matched = 1;
9564: }
9565: }
9566: if ($matched) {
1.167 albertel 9567: $srch_results{$user} =
9568: {&Apache::lonnet::get('environment',
9569: ['firstname',
9570: 'lastname',
1.194 albertel 9571: 'permanentemail'],
9572: $cudomain,$cuname)};
1.162 raeburn 9573: }
9574: }
9575: }
1.179 raeburn 9576: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9577: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9578: }
9579: }
9580: }
9581: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9582: $currstate = 'query';
1.160 raeburn 9583: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9584: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9585: if ($dirsrchres eq 'ok') {
9586: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9587: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9588: } else {
9589: my $showdom = &display_domain_info($srch->{'srchdomain'});
9590: $response = '<span class="LC_warning">'.
9591: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9592: '</span><br />'.
9593: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 9594: '<br />';
1.181 raeburn 9595: }
1.160 raeburn 9596: }
9597: } else {
9598: if ($srch->{'srchin'} eq 'dom') {
9599: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9600: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9601: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9602: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 9603: my $courseusers = &get_courseusers();
9604: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 9605: my ($uname,$udom) = split(/:/,$user);
9606: my %names = &Apache::loncommon::getnames($uname,$udom);
9607: my %emails = &Apache::loncommon::getemails($uname,$udom);
9608: if ($srch->{'srchby'} eq 'lastname') {
9609: if ((($srch->{'srchtype'} eq 'exact') &&
9610: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 9611: (($srch->{'srchtype'} eq 'begins') &&
9612: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 9613: (($srch->{'srchtype'} eq 'contains') &&
9614: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
9615: $srch_results{$user} = {firstname => $names{'firstname'},
9616: lastname => $names{'lastname'},
9617: permanentemail => $emails{'permanentemail'},
9618: };
9619: }
9620: } elsif ($srch->{'srchby'} eq 'lastfirst') {
9621: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 9622: $srchlast =~ s/\s+$//;
9623: $srchfirst =~ s/^\s+//;
1.160 raeburn 9624: if ($srch->{'srchtype'} eq 'exact') {
9625: if (($names{'lastname'} eq $srchlast) &&
9626: ($names{'firstname'} eq $srchfirst)) {
9627: $srch_results{$user} = {firstname => $names{'firstname'},
9628: lastname => $names{'lastname'},
9629: permanentemail => $emails{'permanentemail'},
9630:
9631: };
9632: }
1.177 raeburn 9633: } elsif ($srch->{'srchtype'} eq 'begins') {
9634: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
9635: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
9636: $srch_results{$user} = {firstname => $names{'firstname'},
9637: lastname => $names{'lastname'},
9638: permanentemail => $emails{'permanentemail'},
9639: };
9640: }
9641: } else {
1.160 raeburn 9642: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
9643: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
9644: $srch_results{$user} = {firstname => $names{'firstname'},
9645: lastname => $names{'lastname'},
9646: permanentemail => $emails{'permanentemail'},
9647: };
9648: }
9649: }
9650: }
9651: }
1.179 raeburn 9652: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9653: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9654: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9655: $currstate = 'query';
1.160 raeburn 9656: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9657: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9658: if ($dirsrchres eq 'ok') {
9659: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9660: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9661: } else {
1.406.2.5 raeburn 9662: my $showdom = &display_domain_info($srch->{'srchdomain'});
9663: $response = '<span class="LC_warning">'.
1.181 raeburn 9664: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9665: '</span><br />'.
9666: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 9667: '<br />';
1.181 raeburn 9668: }
1.160 raeburn 9669: }
9670: }
1.179 raeburn 9671: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 9672: }
9673:
1.406.2.3 raeburn 9674: sub domdirectorysrch_check {
9675: my ($srch) = @_;
9676: my $response;
9677: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
9678: ['directorysrch'],$srch->{'srchdomain'});
9679: my $showdom = &display_domain_info($srch->{'srchdomain'});
9680: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
9681: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
9682: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
9683: }
9684: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
9685: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
9686: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
9687: }
9688: }
9689: }
9690: return 'ok';
9691: }
9692:
9693: sub instdirectorysrch_check {
1.160 raeburn 9694: my ($srch) = @_;
9695: my $can_search = 0;
9696: my $response;
9697: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
9698: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 9699: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 9700: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
9701: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 9702: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 9703: }
9704: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
9705: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 9706: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 9707: }
9708: my @usertypes = split(/:/,$env{'environment.inststatus'});
9709: if (!@usertypes) {
9710: push(@usertypes,'default');
9711: }
9712: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
9713: foreach my $type (@usertypes) {
9714: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
9715: $can_search = 1;
9716: last;
9717: }
9718: }
9719: }
9720: if (!$can_search) {
9721: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
9722: my @longtypes;
9723: foreach my $item (@usertypes) {
1.229 raeburn 9724: if (defined($insttypes->{$item})) {
9725: push (@longtypes,$insttypes->{$item});
9726: } elsif ($item eq 'default') {
9727: push (@longtypes,&mt('other'));
9728: }
1.160 raeburn 9729: }
9730: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 9731: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 9732: }
1.160 raeburn 9733: } else {
9734: $can_search = 1;
9735: }
9736: } else {
1.180 raeburn 9737: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 9738: }
9739: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 9740: uname => 'username',
1.160 raeburn 9741: lastfirst => 'last name, first name',
1.167 albertel 9742: lastname => 'last name',
1.172 raeburn 9743: contains => 'contains',
1.178 raeburn 9744: exact => 'as exact match to',
9745: begins => 'begins with',
1.160 raeburn 9746: );
9747: if ($can_search) {
9748: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
9749: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 9750: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 9751: }
9752: } else {
1.180 raeburn 9753: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 9754: }
9755: }
9756: if ($can_search) {
1.178 raeburn 9757: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
9758: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
9759: return 'ok';
9760: } else {
1.180 raeburn 9761: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 9762: }
9763: } else {
9764: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
9765: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
9766: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
9767: return 'ok';
9768: } else {
1.180 raeburn 9769: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 9770: }
1.160 raeburn 9771: }
9772: }
9773: }
9774:
9775: sub get_courseusers {
9776: my %advhash;
1.167 albertel 9777: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 9778: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
9779: foreach my $role (sort(keys(%coursepersonnel))) {
9780: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 9781: if (!exists($classlist->{$user})) {
9782: $classlist->{$user} = [];
9783: }
1.160 raeburn 9784: }
9785: }
1.167 albertel 9786: return $classlist;
1.160 raeburn 9787: }
9788:
9789: sub build_search_response {
1.221 raeburn 9790: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 9791: my ($currstate,$response,$forcenewuser);
1.160 raeburn 9792: my %names = (
1.330 bisitz 9793: 'uname' => 'username',
9794: 'lastname' => 'last name',
1.160 raeburn 9795: 'lastfirst' => 'last name, first name',
1.330 bisitz 9796: 'crs' => 'this course',
9797: 'dom' => 'LON-CAPA domain',
9798: 'instd' => 'the institutional directory for domain',
1.160 raeburn 9799: );
9800:
9801: my %single = (
1.180 raeburn 9802: begins => 'A match',
1.160 raeburn 9803: contains => 'A match',
1.180 raeburn 9804: exact => 'An exact match',
1.160 raeburn 9805: );
9806: my %nomatch = (
1.180 raeburn 9807: begins => 'No match',
1.160 raeburn 9808: contains => 'No match',
1.180 raeburn 9809: exact => 'No exact match',
1.160 raeburn 9810: );
9811: if (keys(%srch_results) > 1) {
1.179 raeburn 9812: $currstate = 'select';
1.160 raeburn 9813: } else {
9814: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 9815: if ($env{'form.action'} eq 'accesslogs') {
9816: $currstate = 'activity';
9817: } else {
9818: $currstate = 'modify';
9819: }
1.180 raeburn 9820: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
9821: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 9822: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 9823: }
1.330 bisitz 9824: } else { # Search has nothing found. Prepare message to user.
9825: $response = '<span class="LC_warning">';
1.180 raeburn 9826: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 9827: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
9828: '<b>'.$srch->{'srchterm'}.'</b>',
9829: &display_domain_info($srch->{'srchdomain'}));
9830: } else {
9831: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
9832: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 9833: }
9834: $response .= '</span>';
1.330 bisitz 9835:
1.160 raeburn 9836: if ($srch->{'srchin'} ne 'alc') {
9837: $forcenewuser = 1;
9838: my $cansrchinst = 0;
1.406.2.14 raeburn 9839: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 9840: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
9841: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9842: if ($domconfig{'directorysrch'}{'available'}) {
9843: $cansrchinst = 1;
9844: }
9845: }
9846: }
1.180 raeburn 9847: if ((($srch->{'srchby'} eq 'lastfirst') ||
9848: ($srch->{'srchby'} eq 'lastname')) &&
9849: ($srch->{'srchin'} eq 'dom')) {
9850: if ($cansrchinst) {
9851: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 9852: }
9853: }
1.180 raeburn 9854: if ($srch->{'srchin'} eq 'crs') {
9855: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
9856: }
9857: }
1.305 raeburn 9858: my $createdom = $env{'request.role.domain'};
9859: if ($context eq 'requestcrs') {
9860: if ($env{'form.coursedom'} ne '') {
9861: $createdom = $env{'form.coursedom'};
9862: }
9863: }
1.406.2.5 raeburn 9864: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
9865: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 9866: my $cancreate =
1.305 raeburn 9867: &Apache::lonuserutils::can_create_user($createdom,$context);
9868: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 9869: if ($cancreate) {
1.305 raeburn 9870: my $showdom = &display_domain_info($createdom);
1.266 bisitz 9871: $response .= '<br /><br />'
9872: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 9873: .'<br />';
9874: if ($context eq 'requestcrs') {
9875: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
9876: } else {
9877: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
9878: }
9879: $response .='<ul><li>'
1.266 bisitz 9880: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
9881: .'</li><li>'
9882: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
9883: .'</li><li>'
9884: .&mt('Provide the proposed username')
9885: .'</li><li>'
9886: .&mt("Click 'Search'")
9887: .'</li></ul><br />';
1.221 raeburn 9888: } else {
1.406.2.7 raeburn 9889: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
9890: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
9891: $response .= '<br /><br />';
9892: if ($context eq 'requestcrs') {
9893: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
9894: } else {
9895: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
9896: }
9897: $response .= '<br />'
9898: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
9899: ,' <a'.$helplink.'>'
9900: ,'</a>')
9901: .'<br />';
1.305 raeburn 9902: }
1.221 raeburn 9903: }
1.160 raeburn 9904: }
9905: }
9906: }
1.179 raeburn 9907: return ($currstate,$response,$forcenewuser);
1.160 raeburn 9908: }
9909:
1.180 raeburn 9910: sub display_domain_info {
9911: my ($dom) = @_;
9912: my $output = $dom;
9913: if ($dom ne '') {
9914: my $domdesc = &Apache::lonnet::domain($dom,'description');
9915: if ($domdesc ne '') {
9916: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
9917: }
9918: }
9919: return $output;
9920: }
9921:
1.160 raeburn 9922: sub crumb_utilities {
9923: my %elements = (
9924: crtuser => {
9925: srchterm => 'text',
1.172 raeburn 9926: srchin => 'selectbox',
1.160 raeburn 9927: srchby => 'selectbox',
9928: srchtype => 'selectbox',
9929: srchdomain => 'selectbox',
9930: },
1.207 raeburn 9931: crtusername => {
9932: srchterm => 'text',
9933: srchdomain => 'selectbox',
9934: },
1.160 raeburn 9935: docustom => {
9936: rolename => 'selectbox',
9937: newrolename => 'textbox',
9938: },
1.179 raeburn 9939: studentform => {
9940: srchterm => 'text',
9941: srchin => 'selectbox',
9942: srchby => 'selectbox',
9943: srchtype => 'selectbox',
9944: srchdomain => 'selectbox',
9945: },
1.160 raeburn 9946: );
9947:
9948: my $jsback .= qq|
9949: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9950: if (typeof prevphase == 'undefined') {
9951: formname.phase.value = '';
9952: }
9953: else {
9954: formname.phase.value = prevphase;
9955: }
9956: if (typeof prevstate == 'undefined') {
9957: formname.currstate.value = '';
9958: }
9959: else {
9960: formname.currstate.value = prevstate;
9961: }
1.160 raeburn 9962: formname.submit();
9963: }
9964: |;
9965: return ($jsback,\%elements);
9966: }
9967:
1.26 matthew 9968: sub course_level_table {
1.375 raeburn 9969: my ($inccourses,$showcredits,$defaultcredits) = @_;
9970: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 9971: my $table = '';
1.62 www 9972: # Custom Roles?
9973:
1.190 raeburn 9974: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 9975: my %lt=&Apache::lonlocal::texthash(
9976: 'exs' => "Existing sections",
9977: 'new' => "Define new section",
9978: 'ssd' => "Set Start Date",
9979: 'sed' => "Set End Date",
1.131 raeburn 9980: 'crl' => "Course Level",
1.89 raeburn 9981: 'act' => "Activate",
9982: 'rol' => "Role",
9983: 'ext' => "Extent",
1.113 raeburn 9984: 'grs' => "Section",
1.375 raeburn 9985: 'crd' => "Credits",
1.89 raeburn 9986: 'sta' => "Start",
9987: 'end' => "End"
9988: );
1.62 www 9989:
1.375 raeburn 9990: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 9991: my $thiscourse=$protectedcourse;
1.26 matthew 9992: $thiscourse=~s:_:/:g;
9993: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 9994: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 9995: my $area=$coursedata{'description'};
1.321 raeburn 9996: my $crstype=$coursedata{'type'};
1.135 raeburn 9997: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 9998: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 9999: my %sections_count;
1.101 albertel 10000: if (defined($env{'request.course.id'})) {
10001: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 10002: %sections_count =
10003: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 10004: }
10005: }
1.321 raeburn 10006: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 10007: foreach my $role (@roles) {
1.321 raeburn 10008: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 10009: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
10010: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 10011: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10012: $plrole,\%sections_count,\%lt,
1.402 raeburn 10013: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10014: } elsif ($env{'request.course.sec'} ne '') {
10015: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
10016: $env{'request.course.sec'})) {
10017: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10018: $plrole,\%sections_count,\%lt,
1.402 raeburn 10019: $showcredits,$defaultcredits,$crstype);
1.26 matthew 10020: }
10021: }
10022: }
1.221 raeburn 10023: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 10024: foreach my $cust (sort(keys(%customroles))) {
10025: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 10026: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
10027: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 10028: $cust,\%sections_count,\%lt,
10029: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10030: }
1.62 www 10031: }
1.26 matthew 10032: }
10033: return '' if ($table eq ''); # return nothing if there is nothing
10034: # in the table
1.188 raeburn 10035: my $result;
10036: if (!$env{'request.course.id'}) {
10037: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
10038: }
10039: $result .=
1.136 raeburn 10040: &Apache::loncommon::start_data_table().
10041: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10042: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 10043: '<th>'.$lt{'ext'}.'</th><th>'."\n";
10044: if ($showcredits) {
10045: $result .= $lt{'crd'}.'</th>';
10046: }
10047: $result .=
1.375 raeburn 10048: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
10049: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 10050: &Apache::loncommon::end_data_table_header_row().
10051: $table.
10052: &Apache::loncommon::end_data_table();
1.26 matthew 10053: return $result;
10054: }
1.88 raeburn 10055:
1.221 raeburn 10056: sub course_level_row {
1.375 raeburn 10057: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 10058: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 10059: my $creditem;
1.222 raeburn 10060: my $row = &Apache::loncommon::start_data_table_row().
10061: ' <td><input type="checkbox" name="act_'.
10062: $protectedcourse.'_'.$role.'" /></td>'."\n".
10063: ' <td>'.$plrole.'</td>'."\n".
10064: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 10065: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 10066: $row .=
10067: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
10068: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
10069: } else {
10070: $row .= '<td> </td>';
10071: }
1.322 raeburn 10072: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 10073: $row .= '<td> </td>';
1.221 raeburn 10074: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 10075: $row .= ' <td><input type="hidden" value="'.
10076: $env{'request.course.sec'}.'" '.
10077: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
10078: $env{'request.course.sec'}.'</td>';
1.221 raeburn 10079: } else {
10080: if (ref($sections_count) eq 'HASH') {
10081: my $currsec =
10082: &Apache::lonuserutils::course_sections($sections_count,
10083: $protectedcourse.'_'.$role);
1.222 raeburn 10084: $row .= '<td><table class="LC_createuser">'."\n".
10085: '<tr class="LC_section_row">'."\n".
10086: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
10087: $currsec.'</td>'."\n".
10088: ' <td> </td>'."\n".
10089: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 10090: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
10091: '" value="" />'.
10092: '<input type="hidden" '.
10093: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 10094: '</tr></table></td>'."\n";
1.221 raeburn 10095: } else {
1.222 raeburn 10096: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 10097: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 10098: }
10099: }
1.222 raeburn 10100: $row .= <<ENDTIMEENTRY;
10101: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 10102: <a href=
10103: "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 10104: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 10105: <a href=
10106: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
10107: ENDTIMEENTRY
1.222 raeburn 10108: $row .= &Apache::loncommon::end_data_table_row();
10109: return $row;
1.221 raeburn 10110: }
10111:
1.88 raeburn 10112: sub course_level_dc {
1.375 raeburn 10113: my ($dcdom,$showcredits) = @_;
1.190 raeburn 10114: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 10115: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 10116: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
10117: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 10118: '<input type="hidden" name="dccourse" value="" />';
1.355 www 10119: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 10120: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 10121: my $credit_elem;
10122: if ($showcredits) {
10123: $credit_elem = 'credits';
10124: }
10125: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 10126: my %lt=&Apache::lonlocal::texthash(
10127: 'rol' => "Role",
1.113 raeburn 10128: 'grs' => "Section",
1.88 raeburn 10129: 'exs' => "Existing sections",
10130: 'new' => "Define new section",
10131: 'sta' => "Start",
10132: 'end' => "End",
10133: 'ssd' => "Set Start Date",
1.355 www 10134: 'sed' => "Set End Date",
1.375 raeburn 10135: 'scc' => "Course/Community",
10136: 'crd' => "Credits",
1.88 raeburn 10137: );
1.323 raeburn 10138: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 10139: &Apache::loncommon::start_data_table().
10140: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10141: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 10142: '<th>'.$lt{'grs'}.'</th>'."\n";
10143: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
10144: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 10145: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 10146: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 10147: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
10148: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 10149: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 10150: foreach my $role (@roles) {
1.135 raeburn 10151: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 10152: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 10153: }
1.404 raeburn 10154: if ( keys(%customroles) > 0) {
10155: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 10156: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 10157: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 10158: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 10159: }
10160: }
10161: $otheritems .= '</select></td><td>'.
10162: '<table border="0" cellspacing="0" cellpadding="0">'.
10163: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 10164: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 10165: '<td> </td>'.
10166: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 10167: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 10168: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 10169: '<input type="hidden" name="groups" value="" />'.
10170: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 10171: '</tr></table></td>'."\n";
10172: if ($showcredits) {
10173: $otheritems .= '<td><br />'."\n".
1.397 bisitz 10174: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 10175: }
1.88 raeburn 10176: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 10177: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 10178: <a href=
10179: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 10180: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 10181: <a href=
10182: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
10183: ENDTIMEENTRY
1.136 raeburn 10184: $otheritems .= &Apache::loncommon::end_data_table_row().
10185: &Apache::loncommon::end_data_table()."\n";
1.406.2.20.2. (raeburn 10186:): return $cb_jscript.$hiddenitems.$header.$otheritems;
1.88 raeburn 10187: }
10188:
1.237 raeburn 10189: sub update_selfenroll_config {
1.400 raeburn 10190: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 10191: return unless (ref($currsettings) eq 'HASH');
10192: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
10193: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 10194: my (%changes,%warning);
1.241 raeburn 10195: my $curr_types;
1.400 raeburn 10196: my %noedit;
10197: unless ($context eq 'domain') {
10198: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
10199: }
1.237 raeburn 10200: if (ref($row) eq 'ARRAY') {
10201: foreach my $item (@{$row}) {
1.400 raeburn 10202: next if ($noedit{$item});
1.237 raeburn 10203: if ($item eq 'enroll_dates') {
10204: my (%currenrolldate,%newenrolldate);
10205: foreach my $type ('start','end') {
1.398 raeburn 10206: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 10207: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
10208: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
10209: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
10210: }
10211: }
10212: } elsif ($item eq 'access_dates') {
10213: my (%currdate,%newdate);
10214: foreach my $type ('start','end') {
1.398 raeburn 10215: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 10216: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
10217: if ($newdate{$type} ne $currdate{$type}) {
10218: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
10219: }
10220: }
1.241 raeburn 10221: } elsif ($item eq 'types') {
1.398 raeburn 10222: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 10223: if ($env{'form.selfenroll_all'}) {
10224: if ($curr_types ne '*') {
10225: $changes{'internal.selfenroll_types'} = '*';
10226: } else {
10227: next;
10228: }
10229: } else {
1.249 raeburn 10230: my %currdoms;
1.241 raeburn 10231: my @entries = split(/;/,$curr_types);
10232: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 10233: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 10234: my $newnum = 0;
1.249 raeburn 10235: my @latesttypes;
10236: foreach my $num (@activations) {
10237: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
10238: if (@types > 0) {
1.241 raeburn 10239: @types = sort(@types);
10240: my $typestr = join(',',@types);
1.249 raeburn 10241: my $typedom = $env{'form.selfenroll_dom_'.$num};
10242: $latesttypes[$newnum] = $typedom.':'.$typestr;
10243: $currdoms{$typedom} = 1;
1.241 raeburn 10244: $newnum ++;
10245: }
10246: }
1.338 raeburn 10247: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
10248: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 10249: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
10250: if (@types > 0) {
10251: @types = sort(@types);
10252: my $typestr = join(',',@types);
10253: my $typedom = $env{'form.selfenroll_dom_'.$j};
10254: $latesttypes[$newnum] = $typedom.':'.$typestr;
10255: $currdoms{$typedom} = 1;
10256: $newnum ++;
10257: }
10258: }
10259: }
10260: if ($env{'form.selfenroll_newdom'} ne '') {
10261: my $typedom = $env{'form.selfenroll_newdom'};
10262: if ((!defined($currdoms{$typedom})) &&
10263: (&Apache::lonnet::domain($typedom) ne '')) {
10264: my $typestr;
10265: my ($othertitle,$usertypes,$types) =
10266: &Apache::loncommon::sorted_inst_types($typedom);
10267: my $othervalue = 'any';
10268: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
10269: if (@{$types} > 0) {
1.257 raeburn 10270: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 10271: $othervalue = 'other';
1.258 raeburn 10272: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 10273: }
10274: $typestr = $othervalue;
10275: } else {
10276: $typestr = $othervalue;
10277: }
10278: $latesttypes[$newnum] = $typedom.':'.$typestr;
10279: $newnum ++ ;
10280: }
10281: }
1.241 raeburn 10282: my $selfenroll_types = join(';',@latesttypes);
10283: if ($selfenroll_types ne $curr_types) {
10284: $changes{'internal.selfenroll_types'} = $selfenroll_types;
10285: }
10286: }
1.276 raeburn 10287: } elsif ($item eq 'limit') {
10288: my $newlimit = $env{'form.selfenroll_limit'};
10289: my $newcap = $env{'form.selfenroll_cap'};
10290: $newcap =~s/\s+//g;
1.398 raeburn 10291: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10292: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 10293: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10294: if ($newlimit ne $currlimit) {
10295: if ($newlimit ne 'none') {
10296: if ($newcap =~ /^\d+$/) {
10297: if ($newcap ne $currcap) {
10298: $changes{'internal.selfenroll_cap'} = $newcap;
10299: }
10300: $changes{'internal.selfenroll_limit'} = $newlimit;
10301: } else {
1.398 raeburn 10302: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10303: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10304: }
10305: } elsif ($currcap ne '') {
10306: $changes{'internal.selfenroll_cap'} = '';
10307: $changes{'internal.selfenroll_limit'} = $newlimit;
10308: }
10309: } elsif ($currlimit ne 'none') {
10310: if ($newcap =~ /^\d+$/) {
10311: if ($newcap ne $currcap) {
10312: $changes{'internal.selfenroll_cap'} = $newcap;
10313: }
10314: } else {
1.398 raeburn 10315: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10316: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10317: }
10318: }
10319: } elsif ($item eq 'approval') {
10320: my (@currnotified,@newnotified);
1.398 raeburn 10321: my $currapproval = $currsettings->{'selfenroll_approval'};
10322: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10323: if ($currnotifylist ne '') {
10324: @currnotified = split(/,/,$currnotifylist);
10325: @currnotified = sort(@currnotified);
10326: }
10327: my $newapproval = $env{'form.selfenroll_approval'};
10328: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
10329: @newnotified = sort(@newnotified);
10330: if ($newapproval ne $currapproval) {
10331: $changes{'internal.selfenroll_approval'} = $newapproval;
10332: if (!$newapproval) {
10333: if ($currnotifylist ne '') {
10334: $changes{'internal.selfenroll_notifylist'} = '';
10335: }
10336: } else {
10337: my @differences =
1.295 raeburn 10338: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10339: if (@differences > 0) {
10340: if (@newnotified > 0) {
10341: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10342: } else {
10343: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10344: }
10345: }
10346: }
10347: } else {
1.295 raeburn 10348: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10349: if (@differences > 0) {
10350: if (@newnotified > 0) {
10351: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10352: } else {
10353: $changes{'internal.selfenroll_notifylist'} = '';
10354: }
10355: }
10356: }
1.237 raeburn 10357: } else {
1.398 raeburn 10358: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 10359: my $newval = $env{'form.selfenroll_'.$item};
10360: if ($item eq 'section') {
10361: $newval = $env{'form.sections'};
1.241 raeburn 10362: if (defined($curr_groups{$newval})) {
1.237 raeburn 10363: $newval = $curr_val;
1.398 raeburn 10364: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
10365: &mt('Group names and section names must be distinct');
1.237 raeburn 10366: } elsif ($newval eq 'all') {
10367: $newval = $curr_val;
1.274 bisitz 10368: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 10369: }
10370: if ($newval eq '') {
10371: $newval = 'none';
10372: }
10373: }
10374: if ($newval ne $curr_val) {
10375: $changes{'internal.selfenroll_'.$item} = $newval;
10376: }
1.241 raeburn 10377: }
1.237 raeburn 10378: }
10379: if (keys(%warning) > 0) {
10380: foreach my $item (@{$row}) {
10381: if (exists($warning{$item})) {
10382: $r->print($warning{$item}.'<br />');
10383: }
10384: }
10385: }
10386: if (keys(%changes) > 0) {
10387: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
10388: if ($putresult eq 'ok') {
10389: if ((exists($changes{'internal.selfenroll_types'})) ||
10390: (exists($changes{'internal.selfenroll_start_date'})) ||
10391: (exists($changes{'internal.selfenroll_end_date'}))) {
10392: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
10393: $cnum,undef,undef,'Course');
10394: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 10395: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 10396: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
10397: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 10398: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 10399: }
10400: }
10401: my $crsputresult =
10402: &Apache::lonnet::courseidput($cdom,\%crsinfo,
10403: $chome,'notime');
10404: }
10405: }
10406: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
10407: foreach my $item (@{$row}) {
10408: my $title = $item;
10409: if (ref($lt) eq 'HASH') {
10410: $title = $lt->{$item};
10411: }
10412: if ($item eq 'enroll_dates') {
10413: foreach my $type ('start','end') {
10414: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
10415: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 10416: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10417: $title,$type,$newdate).'</li>');
10418: }
10419: }
10420: } elsif ($item eq 'access_dates') {
10421: foreach my $type ('start','end') {
10422: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
10423: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 10424: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10425: $title,$type,$newdate).'</li>');
10426: }
10427: }
1.276 raeburn 10428: } elsif ($item eq 'limit') {
10429: if ((exists($changes{'internal.selfenroll_limit'})) ||
10430: (exists($changes{'internal.selfenroll_cap'}))) {
10431: my ($newval,$newcap);
10432: if ($changes{'internal.selfenroll_cap'} ne '') {
10433: $newcap = $changes{'internal.selfenroll_cap'}
10434: } else {
1.398 raeburn 10435: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10436: }
10437: if ($changes{'internal.selfenroll_limit'} eq 'none') {
10438: $newval = &mt('No limit');
10439: } elsif ($changes{'internal.selfenroll_limit'} eq
10440: 'allstudents') {
10441: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10442: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
10443: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
10444: } else {
1.398 raeburn 10445: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10446: if ($currlimit eq 'allstudents') {
10447: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10448: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 10449: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 10450: }
10451: }
10452: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
10453: }
10454: } elsif ($item eq 'approval') {
10455: if ((exists($changes{'internal.selfenroll_approval'})) ||
10456: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 10457: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 10458: my ($newval,$newnotify);
10459: if (exists($changes{'internal.selfenroll_notifylist'})) {
10460: $newnotify = $changes{'internal.selfenroll_notifylist'};
10461: } else {
1.398 raeburn 10462: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10463: }
1.398 raeburn 10464: if (exists($changes{'internal.selfenroll_approval'})) {
10465: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
10466: $changes{'internal.selfenroll_approval'} = '0';
10467: }
10468: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 10469: } else {
1.398 raeburn 10470: my $currapproval = $currsettings->{'selfenroll_approval'};
10471: if ($currapproval !~ /^[012]$/) {
10472: $currapproval = 0;
1.276 raeburn 10473: }
1.398 raeburn 10474: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 10475: }
10476: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
10477: if ($newnotify) {
1.277 raeburn 10478: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 10479: } else {
1.277 raeburn 10480: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 10481: }
10482: $r->print('</li>'."\n");
10483: }
1.237 raeburn 10484: } else {
10485: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 10486: my $newval = $changes{'internal.selfenroll_'.$item};
10487: if ($item eq 'types') {
10488: if ($newval eq '') {
10489: $newval = &mt('None');
10490: } elsif ($newval eq '*') {
10491: $newval = &mt('Any user in any domain');
10492: }
1.245 raeburn 10493: } elsif ($item eq 'registered') {
10494: if ($newval eq '1') {
10495: $newval = &mt('Yes');
10496: } elsif ($newval eq '0') {
10497: $newval = &mt('No');
10498: }
1.241 raeburn 10499: }
1.244 bisitz 10500: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 10501: }
10502: }
10503: }
10504: $r->print('</ul>');
1.398 raeburn 10505: if ($env{'course.'.$cid.'.description'} ne '') {
10506: my %newenvhash;
10507: foreach my $key (keys(%changes)) {
10508: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
10509: }
10510: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 10511: }
10512: } else {
1.398 raeburn 10513: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
10514: &mt('The error was: [_1].',$putresult));
1.237 raeburn 10515: }
10516: } else {
1.249 raeburn 10517: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 10518: }
10519: } else {
1.249 raeburn 10520: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 10521: }
1.406.2.20.2. (raeburn 10522:): my $visactions = &cat_visibility($cdom);
1.400 raeburn 10523: my ($cathash,%cattype);
10524: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
10525: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10526: $cathash = $domconfig{'coursecategories'}{'cats'};
10527: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
10528: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
10529: } else {
10530: $cathash = {};
10531: $cattype{'auth'} = 'std';
10532: $cattype{'unauth'} = 'std';
10533: }
10534: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
10535: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10536: '<br />'.
10537: '<br />'.$visactions->{'take'}.'<ul>'.
10538: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
10539: '</ul>');
10540: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
10541: if ($currsettings->{'uniquecode'}) {
10542: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
10543: } else {
1.366 bisitz 10544: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 10545: '<br />'.
10546: '<br />'.$visactions->{'take'}.'<ul>'.
10547: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
10548: '</ul><br />');
10549: }
10550: } else {
10551: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
10552: if (ref($visactions) eq 'HASH') {
10553: if (!$visible) {
10554: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10555: '<br />');
10556: if (ref($vismsgs) eq 'ARRAY') {
10557: $r->print('<br />'.$visactions->{'take'}.'<ul>');
10558: foreach my $item (@{$vismsgs}) {
10559: $r->print('<li>'.$visactions->{$item}.'</li>');
10560: }
10561: $r->print('</ul>');
1.256 raeburn 10562: }
1.400 raeburn 10563: $r->print($cansetvis);
1.256 raeburn 10564: }
10565: }
10566: }
1.237 raeburn 10567: return;
10568: }
10569:
1.27 matthew 10570: #---------------------------------------------- end functions for &phase_two
1.29 matthew 10571:
10572: #--------------------------------- functions for &phase_two and &phase_three
10573:
10574: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 10575:
1.1 www 10576: 1;
10577: __END__
1.2 www 10578:
10579:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>