Annotation of loncom/interface/loncreateuser.pm, revision 1.406.2.20.2.8
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.7 2024/09/01 02:28:19 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:): $curr_access = $userenv{'tools.'.$item};
373:): } else {
374:): $curr_access =
375:): &Apache::lonnet::usertools_access($ccuname,$ccdomain,$item,'reload',
376:): undef,\%userenv,'',
377:): {'is_adv' => $isadv});
378:): }
379:): }
1.362 raeburn 380: } elsif ($userenv{$context.'.'.$item} ne '') {
1.306 raeburn 381: $cust_on = ' checked="checked" ';
382: $cust_off = '';
383: }
384: if ($context eq 'requestcourses') {
385: if ($userenv{$context.'.'.$item} eq '') {
1.314 raeburn 386: $custom_access = &mt('Currently from default setting.');
1.406.2.20.2. (raeburn 387:): $customsty = ' style="display:none;"';
1.306 raeburn 388: } else {
389: $custom_access = &mt('Currently from custom setting.');
1.406.2.20.2. (raeburn 390:): $customsty = ' style="display:block;"';
1.275 raeburn 391: }
1.362 raeburn 392: } elsif ($context eq 'requestauthor') {
393: if ($userenv{$context} eq '') {
394: $custom_access = &mt('Currently from default setting.');
1.406.2.20.2. (raeburn 395:): $customsty = ' style="display:none;"';
1.362 raeburn 396: } else {
397: $custom_access = &mt('Currently from custom setting.');
1.406.2.20.2. (raeburn 398:): $customsty = ' style="display:block;"';
399:): }
400:): } elsif ($item eq 'editors') {
401:): if ($userenv{'author'.$item} eq '') {
402:): if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
403:): @defaulteditors = @{$domconfig{'authordefaults'}{'editors'}};
404:): } else {
405:): @defaulteditors = ('edit','xml');
406:): }
407:): $custom_access = &mt('Can use: [_1]',
408:): join(', ', map { $lt{$_} } @defaulteditors));
409:): $editorsty = ' style="display:none;"';
410:): } else {
411:): $custom_access = &mt('Currently from custom setting.');
412:): foreach my $editor (split(/,/,$userenv{'author'.$item})) {
413:): if ($editor =~ /^(edit|daxe|xml)$/) {
414:): push(@customeditors,$editor);
415:): }
416:): }
417:): if (@customeditors) {
418:): if (@customeditors > 1) {
419:): $custom_access .= '<br /><span>';
420:): } else {
421:): $custom_access .= ' <span class="LC_nobreak">';
422:): }
423:): $custom_access .= &mt('Can use: [_1]',
424:): join(', ', map { $lt{$_} } @customeditors)).
425:): '</span>';
426:): } else {
427:): $custom_access .= ' '.&mt('No available editors');
428:): }
429:): $editorsty = ' style="display:block;"';
1.362 raeburn 430: }
1.406.2.20.2. (raeburn 431:): } elsif ($item eq 'managers') {
432:): my %ca_roles = &Apache::lonnet::get_my_roles($ccuname,$ccdomain,undef,
433:): ['active','future'],['ca']);
434:): if (keys(%ca_roles)) {
435:): foreach my $entry (sort(keys(%ca_roles))) {
436:): if ($entry =~ /^($match_username\:$match_domain):ca$/) {
437:): my $user = $1;
438:): unless ($user eq "$ccuname:$ccdomain") {
439:): push(@possmanagers,$user);
440:): }
441:): }
442:): }
443:): }
444:): if ($userenv{'author'.$item} eq '') {
445:): $custom_access = &mt('Currently author manages co-author roles');
446:): } else {
447:): if (keys(%ca_roles)) {
448:): foreach my $user (split(/,/,$userenv{'author'.$item})) {
449:): if ($user =~ /^($match_username):($match_domain)$/) {
450:): if (exists($ca_roles{$user.':ca'})) {
451:): unless ($user eq "$ccuname:$ccdomain") {
452:): push(@custommanagers,$user);
453:): }
454:): }
455:): }
456:): }
457:): }
458:): if (@custommanagers) {
459:): $custom_access = &mt('Co-authors who manage co-author roles: [_1]',
460:): join(', ',@custommanagers));
461:): } else {
462:): $custom_access = &mt('Currently author manages co-author roles');
463:): }
464:): }
1.275 raeburn 465: } else {
1.406.2.20.2. (raeburn 466:): my $current = $userenv{$context.'.'.$item};
467:): if ($item eq 'webdav') {
468:): $current = $userenv{'tools.webdav'};
469:): } elsif ($item eq 'archive') {
470:): $current = $userenv{'author'.$item};
471:): }
472:): if ($current eq '') {
1.314 raeburn 473: $custom_access =
1.306 raeburn 474: &mt('Availability determined currently from default setting.');
475: if (!$curr_access) {
476: $tool_off = 'checked="checked" ';
477: $tool_on = '';
478: }
1.406.2.20.2. (raeburn 479:): $customsty = ' style="display:none;"';
1.306 raeburn 480: } else {
1.314 raeburn 481: $custom_access =
1.306 raeburn 482: &mt('Availability determined currently from custom setting.');
1.406.2.20.2. (raeburn 483:): if ($current == 0) {
1.306 raeburn 484: $tool_off = 'checked="checked" ';
485: $tool_on = '';
486: }
1.406.2.20.2. (raeburn 487:): $customsty = ' style="display:inline;"';
1.275 raeburn 488: }
489: }
490: $output .= ' <tr class="LC_info_row">'."\n".
1.306 raeburn 491: ' <td'.$colspan.'>'.$lt{$item}.'</td>'."\n".
1.275 raeburn 492: ' </tr>'."\n".
1.306 raeburn 493: &Apache::loncommon::start_data_table_row()."\n";
1.362 raeburn 494: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.306 raeburn 495: my ($curroption,$currlimit);
1.362 raeburn 496: my $envkey = $context.'.'.$item;
497: if ($context eq 'requestauthor') {
498: $envkey = $context;
499: }
500: if ($userenv{$envkey} ne '') {
501: $curroption = $userenv{$envkey};
1.332 raeburn 502: } else {
503: my (@inststatuses);
1.362 raeburn 504: if ($context eq 'requestcourses') {
505: $curroption =
506: &Apache::loncoursequeueadmin::get_processtype('course',$ccuname,$ccdomain,
507: $isadv,$ccdomain,$item,
508: \@inststatuses,\%domconfig);
509: } else {
510: $curroption =
511: &Apache::loncoursequeueadmin::get_processtype('requestauthor',$ccuname,$ccdomain,
512: $isadv,$ccdomain,undef,
513: \@inststatuses,\%domconfig);
514: }
1.332 raeburn 515: }
1.306 raeburn 516: if (!$curroption) {
517: $curroption = 'norequest';
518: }
1.406.2.20.2. (raeburn 519:): my $name = 'crsreq_'.$item;
520:): if ($context eq 'requestauthor') {
521:): $name = $item;
522:): }
523:): $onclick = ' onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');"';
1.306 raeburn 524: if ($curroption =~ /^autolimit=(\d*)$/) {
525: $currlimit = $1;
1.314 raeburn 526: if ($currlimit eq '') {
527: $currdisp = &mt('Yes, automatic creation');
528: } else {
529: $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
530: }
1.306 raeburn 531: } else {
532: $currdisp = $reqdisplay{$curroption};
533: }
1.406.2.20.2. (raeburn 534:): $custdisp = '<fieldset id="customtext_'.$item.'"'.$customsty.'>';
1.306 raeburn 535: foreach my $option (@options) {
536: my $val = $option;
537: if ($option eq 'norequest') {
538: $val = 0;
539: }
540: if ($option eq 'validate') {
541: my $canvalidate = 0;
542: if (ref($validations{$item}) eq 'HASH') {
543: if ($validations{$item}{'_custom_'}) {
544: $canvalidate = 1;
545: }
546: }
547: next if (!$canvalidate);
548: }
549: my $checked = '';
550: if ($option eq $curroption) {
551: $checked = ' checked="checked"';
552: } elsif ($option eq 'autolimit') {
553: if ($curroption =~ /^autolimit/) {
554: $checked = ' checked="checked"';
555: }
556: }
1.406.2.20.2. (raeburn 557:): if ($option eq 'autolimit') {
558:): $custdisp .= '<br />';
1.362 raeburn 559: }
1.406.2.20.2. (raeburn 560:): $custdisp .= '<span class="LC_nobreak"><label>'.
1.362 raeburn 561: '<input type="radio" name="'.$name.'" '.
562: 'value="'.$val.'"'.$checked.' />'.
1.306 raeburn 563: $reqtitles{$option}.'</label> ';
564: if ($option eq 'autolimit') {
1.362 raeburn 565: $custdisp .= '<input type="text" name="'.$name.
566: '_limit" size="1" '.
1.406.2.20.2. (raeburn 567:): 'value="'.$currlimit.'" /> '.
568:): $reqtitles{'unlimited'}.'</span>';
1.362 raeburn 569: } else {
570: $custdisp .= '</span>';
571: }
1.406.2.20.2. (raeburn 572:): $custdisp .= ' ';
573:): }
574:): $custdisp .= '</fieldset>';
575:): $custradio = '<br />'.$custdisp;
576:): } elsif ($item eq 'editors') {
577:): $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
578:): &Apache::loncommon::end_data_table_row()."\n";
579:): unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
580:): $output .= &Apache::loncommon::start_data_table_row()."\n".
581:): '<td'.$colspan.'><span class="LC_nobreak">'.
582:): $lt{'chse'}.': <label>'.
583:): '<input type="radio" name="custom'.$item.'" value="0" '.
584:): $cust_off.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
585:): $lt{'usde'}.'</label>'.(' ' x3).
586:): '<label><input type="radio" name="custom'.$item.'" value="1" '.
587:): $cust_on.' onclick="toggleCustom(this.form,'."'customtext_$item','custom$item'".');" />'.
588:): $lt{'uscu'}.'</label></span><br />'.
589:): '<fieldset id="customtext_'.$item.'"'.$editorsty.'>';
590:): foreach my $editor ('edit','xml','daxe') {
591:): my $checked;
592:): if ($userenv{'author'.$item} eq '') {
593:): if (grep(/^\Q$editor\E$/,@defaulteditors)) {
594:): $checked = ' checked="checked"';
595:): }
596:): } elsif (grep(/^\Q$editor\E$/,@customeditors)) {
597:): $checked = ' checked="checked"';
598:): }
599:): $output .= '<span style="LC_nobreak"><label>'.
600:): '<input type="checkbox" name="custom_editor" '.
601:): 'value="'.$editor.'"'.$checked.' />'.
602:): $lt{$editor}.'</label></span> ';
603:): }
604:): $output .= '</fieldset></td>'.
605:): &Apache::loncommon::end_data_table_row()."\n";
1.306 raeburn 606: }
1.406.2.20.2. (raeburn 607:): } elsif ($item eq 'managers') {
608:): $output .= '<td'.$colspan.'>'.$custom_access.'</td>'."\n".
609:): &Apache::loncommon::end_data_table_row()."\n";
610:): unless ((&Apache::lonnet::allowed('udp',$ccdomain)) ||
611:): (($userenv{'domcoord.author'} eq 'blocked') &&
612:): (($env{'user.name'} ne $ccuname) || ($env{'user.domain'} ne $ccdomain)))) {
613:): $output .=
614:): &Apache::loncommon::start_data_table_row()."\n".
615:): '<td'.$colspan.'>';
616:): if (@possmanagers) {
617:): $output .= &mt('Select manager(s)').': ';
618:): foreach my $user (@possmanagers) {
619:): my $checked;
620:): if (grep(/^\Q$user\E$/,@custommanagers)) {
621:): $checked = ' checked="checked"';
622:): }
623:): $output .= '<span style="LC_nobreak"><label>'.
624:): '<input type="checkbox" name="custommanagers" '.
625:): 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
626:): $user.'</label></span> ';
627:): }
628:): } else {
629:): $output .= &mt('No co-author roles assignable as manager');
630:): }
631:): $output .= '</td>'.
632:): &Apache::loncommon::end_data_table_row()."\n";
633:): }
1.306 raeburn 634: } else {
635: $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
1.362 raeburn 636: my $name = $context.'_'.$item;
1.406.2.20.2. (raeburn 637:): $onclick = 'onclick="javascript:toggleCustom(this.form,'."'customtext_$item','custom$item'".');" ';
1.306 raeburn 638: $custdisp = '<span class="LC_nobreak"><label>'.
1.362 raeburn 639: '<input type="radio" name="'.$name.'"'.
1.406.2.20.2. (raeburn 640:): ' value="1" '.$tool_on.$onclick.'/>'.&mt('On').'</label> <label>'.
1.362 raeburn 641: '<input type="radio" name="'.$name.'" value="0" '.
1.406.2.20.2. (raeburn 642:): $tool_off.$onclick.'/>'.&mt('Off').'</label></span>';
643:): $custradio = '<span id="customtext_'.$item.'"'.$customsty.' class="LC_nobreak">'.
644:): '--'.$lt{'cusa'}.': '.$custdisp.'</span>';
645:): }
646:): unless (($item eq 'editors') || ($item eq 'managers')) {
647:): $output .= ' <td'.$colspan.'>'.$custom_access.(' 'x4).
648:): $lt{'avai'}.': '.$currdisp.'</td>'."\n".
649:): &Apache::loncommon::end_data_table_row()."\n";
650:): unless (&Apache::lonnet::allowed('udp',$ccdomain)) {
651:): $output .=
1.275 raeburn 652: &Apache::loncommon::start_data_table_row()."\n".
1.406.2.20.2. (raeburn 653:): '<td><span class="LC_nobreak">'.
1.306 raeburn 654: $lt{'chse'}.': <label>'.
1.275 raeburn 655: '<input type="radio" name="custom'.$item.'" value="0" '.
1.406.2.20.2. (raeburn 656:): $cust_off.$onclick.'/>'.$lt{'usde'}.'</label>'.(' ' x3).
1.306 raeburn 657: '<label><input type="radio" name="custom'.$item.'" value="1" '.
1.406.2.20.2. (raeburn 658:): $cust_on.$onclick.'/>'.$lt{'uscu'}.'</label></span>';
659:): if ($colspan) {
660:): $output .= '</td><td>';
661:): }
662:): $output .= $custradio.'</td>'.
663:): &Apache::loncommon::end_data_table_row()."\n";
664:): }
1.406.2.6 raeburn 665: }
1.275 raeburn 666: }
667: return $output;
668: }
669:
1.300 raeburn 670: sub coursereq_externaluser {
671: my ($ccuname,$ccdomain,$cdom) = @_;
1.306 raeburn 672: my (@usertools,@options,%validations,%userenv,$output);
1.300 raeburn 673: my %lt = &Apache::lonlocal::texthash (
674: 'official' => 'Can request creation of official courses',
675: 'unofficial' => 'Can request creation of unofficial courses',
676: 'community' => 'Can request creation of communities',
1.384 raeburn 677: 'textbook' => 'Can request creation of textbook courses',
1.300 raeburn 678: );
679:
680: %userenv = &Apache::lonnet::userenvironment($ccdomain,$ccuname,
681: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.384 raeburn 682: 'reqcrsotherdom.community','reqcrsotherdom.textbook');
683: @usertools = ('official','unofficial','community','textbook');
1.309 raeburn 684: @options = ('approval','validate','autolimit');
1.306 raeburn 685: %validations = &Apache::lonnet::auto_courserequest_checks($cdom);
686: my $optregex = join('|',@options);
687: my %reqtitles = &courserequest_titles();
1.300 raeburn 688: foreach my $item (@usertools) {
1.306 raeburn 689: my ($curroption,$currlimit,$tooloff);
1.300 raeburn 690: if ($userenv{'reqcrsotherdom.'.$item} ne '') {
691: my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
1.314 raeburn 692: foreach my $req (@curr) {
693: if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
694: $curroption = $1;
695: $currlimit = $2;
696: last;
1.306 raeburn 697: }
698: }
1.314 raeburn 699: if (!$curroption) {
700: $curroption = 'norequest';
701: $tooloff = ' checked="checked"';
702: }
1.306 raeburn 703: } else {
704: $curroption = 'norequest';
705: $tooloff = ' checked="checked"';
706: }
707: $output.= &Apache::loncommon::start_data_table_row()."\n".
1.314 raeburn 708: ' <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
709: '<table><tr><td valign="top">'."\n".
1.306 raeburn 710: '<label><input type="radio" name="reqcrsotherdom_'.$item.
1.314 raeburn 711: '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
712: '</label></td>';
1.306 raeburn 713: foreach my $option (@options) {
714: if ($option eq 'validate') {
715: my $canvalidate = 0;
716: if (ref($validations{$item}) eq 'HASH') {
717: if ($validations{$item}{'_external_'}) {
718: $canvalidate = 1;
719: }
720: }
721: next if (!$canvalidate);
722: }
723: my $checked = '';
724: if ($option eq $curroption) {
725: $checked = ' checked="checked"';
726: }
1.314 raeburn 727: $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
1.306 raeburn 728: '<input type="radio" name="reqcrsotherdom_'.$item.
729: '" value="'.$option.'"'.$checked.' />'.
1.314 raeburn 730: $reqtitles{$option}.'</label>';
1.306 raeburn 731: if ($option eq 'autolimit') {
1.314 raeburn 732: $output .= ' <input type="text" name="reqcrsotherdom_'.
1.306 raeburn 733: $item.'_limit" size="1" '.
1.314 raeburn 734: 'value="'.$currlimit.'" /></span>'.
735: '<br />'.$reqtitles{'unlimited'};
736: } else {
737: $output .= '</span>';
1.300 raeburn 738: }
1.314 raeburn 739: $output .= '</td>';
1.300 raeburn 740: }
1.314 raeburn 741: $output .= '</td></tr></table></td>'."\n".
1.300 raeburn 742: &Apache::loncommon::end_data_table_row()."\n";
743: }
744: return $output;
745: }
746:
1.362 raeburn 747: sub domainrole_req {
748: my ($ccuname,$ccdomain) = @_;
749: return '<br /><h3>'.
1.406.2.20.2. (raeburn 750:): &mt('Can Request Assignment of Domain Roles?').
1.362 raeburn 751: '</h3>'."\n".
752: &Apache::loncommon::start_data_table().
753: &build_tools_display($ccuname,$ccdomain,
754: 'requestauthor').
755: &Apache::loncommon::end_data_table();
756: }
757:
1.406.2.20.2. (raeburn 758:): sub authoring_defaults {
759:): my ($ccuname,$ccdomain) = @_;
760:): return '<br /><h3>'.
761:): &mt('Authoring Space defaults (if role assigned)').
762:): '</h3>'."\n".
763:): &Apache::loncommon::start_data_table().
764:): &build_tools_display($ccuname,$ccdomain,
765:): 'authordefaults').
766:): &user_quotas($ccuname,$ccdomain,'author').
767:): &Apache::loncommon::end_data_table();
768:): }
769:):
1.306 raeburn 770: sub courserequest_titles {
771: my %titles = &Apache::lonlocal::texthash (
772: official => 'Official',
773: unofficial => 'Unofficial',
774: community => 'Communities',
1.384 raeburn 775: textbook => 'Textbook',
1.306 raeburn 776: norequest => 'Not allowed',
1.309 raeburn 777: approval => 'Approval by Dom. Coord.',
1.306 raeburn 778: validate => 'With validation',
779: autolimit => 'Numerical limit',
1.314 raeburn 780: unlimited => '(blank for unlimited)',
1.306 raeburn 781: );
782: return %titles;
783: }
784:
785: sub courserequest_display {
786: my %titles = &Apache::lonlocal::texthash (
1.309 raeburn 787: approval => 'Yes, need approval',
1.306 raeburn 788: validate => 'Yes, with validation',
789: norequest => 'No',
790: );
791: return %titles;
792: }
793:
1.362 raeburn 794: sub requestauthor_titles {
795: my %titles = &Apache::lonlocal::texthash (
796: norequest => 'Not allowed',
797: approval => 'Approval by Dom. Coord.',
798: automatic => 'Automatic approval',
799: );
800: return %titles;
801:
802: }
803:
804: sub requestauthor_display {
805: my %titles = &Apache::lonlocal::texthash (
806: approval => 'Yes, need approval',
807: automatic => 'Yes, automatic approval',
808: norequest => 'No',
809: );
810: return %titles;
811: }
812:
1.383 raeburn 813: sub requestchange_display {
814: my %titles = &Apache::lonlocal::texthash (
815: approval => "availability set to 'on' (approval required)",
816: automatic => "availability set to 'on' (automatic approval)",
817: norequest => "availability set to 'off'",
818: );
819: return %titles;
820: }
821:
1.362 raeburn 822: sub curr_requestauthor {
823: my ($uname,$udom,$isadv,$inststatuses,$domconfig) = @_;
824: return unless ((ref($inststatuses) eq 'ARRAY') && (ref($domconfig) eq 'HASH'));
825: if ($uname eq '' || $udom eq '') {
826: $uname = $env{'user.name'};
827: $udom = $env{'user.domain'};
828: $isadv = $env{'user.adv'};
829: }
830: my (%userenv,%settings,$val);
831: my @options = ('automatic','approval');
832: %userenv =
833: &Apache::lonnet::userenvironment($udom,$uname,'requestauthor','inststatus');
834: if ($userenv{'requestauthor'}) {
835: $val = $userenv{'requestauthor'};
836: @{$inststatuses} = ('_custom_');
837: } else {
838: my %alltasks;
839: if (ref($domconfig->{'requestauthor'}) eq 'HASH') {
840: %settings = %{$domconfig->{'requestauthor'}};
841: if (($isadv) && ($settings{'_LC_adv'} ne '')) {
842: $val = $settings{'_LC_adv'};
843: @{$inststatuses} = ('_LC_adv_');
844: } else {
845: if ($userenv{'inststatus'} ne '') {
846: @{$inststatuses} = split(',',$userenv{'inststatus'});
847: } else {
848: @{$inststatuses} = ('default');
849: }
850: foreach my $status (@{$inststatuses}) {
851: if (exists($settings{$status})) {
852: my $value = $settings{$status};
853: next unless ($value);
854: unless (exists($alltasks{$value})) {
855: if (ref($alltasks{$value}) eq 'ARRAY') {
856: unless(grep(/^\Q$status\E$/,@{$alltasks{$value}})) {
857: push(@{$alltasks{$value}},$status);
858: }
859: } else {
860: @{$alltasks{$value}} = ($status);
861: }
862: }
863: }
864: }
865: foreach my $option (@options) {
866: if ($alltasks{$option}) {
867: $val = $option;
868: last;
869: }
870: }
871: }
872: }
873: }
874: return $val;
875: }
876:
1.2 www 877: # =================================================================== Phase one
1.1 www 878:
1.42 matthew 879: sub print_username_entry_form {
1.406.2.14 raeburn 880: my ($r,$context,$response,$srch,$forcenewuser,$crstype,$brcrum,
881: $permission) = @_;
1.101 albertel 882: my $defdom=$env{'request.role.domain'};
1.160 raeburn 883: my $formtoset = 'crtuser';
884: if (exists($env{'form.startrolename'})) {
885: $formtoset = 'docustom';
886: $env{'form.rolename'} = $env{'form.startrolename'};
1.207 raeburn 887: } elsif ($env{'form.origform'} eq 'crtusername') {
888: $formtoset = $env{'form.origform'};
1.160 raeburn 889: }
890:
891: my ($jsback,$elements) = &crumb_utilities();
892:
893: my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
1.165 albertel 894: '<script type="text/javascript">'."\n".
1.301 bisitz 895: '// <![CDATA['."\n".
896: &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset})."\n".
897: '// ]]>'."\n".
1.162 raeburn 898: '</script>'."\n";
1.160 raeburn 899:
1.324 raeburn 900: my %existingroles=&Apache::lonuserutils::my_custom_roles($crstype);
901: if (($env{'form.action'} eq 'custom') && (keys(%existingroles) > 0)
902: && (&Apache::lonnet::allowed('mcr','/'))) {
903: $jscript .= &customrole_javascript();
904: }
1.224 raeburn 905: my $helpitem = 'Course_Change_Privileges';
906: if ($env{'form.action'} eq 'custom') {
1.406.2.14 raeburn 907: if ($context eq 'course') {
908: $helpitem = 'Course_Editing_Custom_Roles';
909: } elsif ($context eq 'domain') {
910: $helpitem = 'Domain_Editing_Custom_Roles';
911: }
1.224 raeburn 912: } elsif ($env{'form.action'} eq 'singlestudent') {
913: $helpitem = 'Course_Add_Student';
1.406.2.5 raeburn 914: } elsif ($env{'form.action'} eq 'accesslogs') {
915: $helpitem = 'Domain_User_Access_Logs';
1.406.2.14 raeburn 916: } elsif ($context eq 'author') {
917: $helpitem = 'Author_Change_Privileges';
918: } elsif ($context eq 'domain') {
919: if ($permission->{'cusr'}) {
920: $helpitem = 'Domain_Change_Privileges';
921: } elsif ($permission->{'view'}) {
922: $helpitem = 'Domain_View_Privileges';
923: } else {
924: undef($helpitem);
925: }
1.224 raeburn 926: }
1.406.2.7 raeburn 927: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$defdom);
1.351 raeburn 928: if ($env{'form.action'} eq 'custom') {
929: push(@{$brcrum},
930: {href=>"javascript:backPage(document.crtuser)",
931: text=>"Pick custom role",
932: help => $helpitem,}
933: );
934: } else {
935: push (@{$brcrum},
936: {href => "javascript:backPage(document.crtuser)",
937: text => $breadcrumb_text{'search'},
938: help => $helpitem,
939: faq => 282,
940: bug => 'Instructor Interface',}
941: );
942: }
943: my %loaditems = (
944: 'onload' => "javascript:setFormElements(document.$formtoset)",
945: );
946: my $args = {bread_crumbs => $brcrum,
947: bread_crumbs_component => 'User Management',
948: add_entries => \%loaditems,};
949: $r->print(&Apache::loncommon::start_page('User Management',$jscript,$args));
950:
1.71 sakharuk 951: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 952: 'srst' => 'Search for a user and enroll as a student',
1.318 raeburn 953: 'srme' => 'Search for a user and enroll as a member',
1.229 raeburn 954: 'srad' => 'Search for a user and modify/add user information or roles',
1.406.2.7 raeburn 955: 'srvu' => 'Search for a user and view user information and roles',
1.406.2.5 raeburn 956: 'srva' => 'Search for a user and view access log information',
1.71 sakharuk 957: 'usr' => "Username",
958: 'dom' => "Domain",
1.324 raeburn 959: 'ecrp' => "Define or Edit Custom Role",
960: 'nr' => "role name",
1.282 schafran 961: 'cre' => "Next",
1.71 sakharuk 962: );
1.351 raeburn 963:
1.214 raeburn 964: if ($env{'form.action'} eq 'custom') {
1.190 raeburn 965: if (&Apache::lonnet::allowed('mcr','/')) {
1.324 raeburn 966: my $newroletext = &mt('Define new custom role:');
967: $r->print('<form action="/adm/createuser" method="post" name="docustom">'.
968: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
969: '<input type="hidden" name="phase" value="selected_custom_edit" />'.
970: '<h3>'.$lt{'ecrp'}.'</h3>'.
971: &Apache::loncommon::start_data_table().
972: &Apache::loncommon::start_data_table_row().
973: '<td>');
974: if (keys(%existingroles) > 0) {
975: $r->print('<br /><label><input type="radio" name="customroleaction" value="new" checked="checked" onclick="setCustomFields();" /><b>'.$newroletext.'</b></label>');
976: } else {
977: $r->print('<br /><input type="hidden" name="customroleaction" value="new" /><b>'.$newroletext.'</b>');
978: }
979: $r->print('</td><td align="center">'.$lt{'nr'}.'<br /><input type="text" size="15" name="newrolename" onfocus="setCustomAction('."'new'".');" /></td>'.
980: &Apache::loncommon::end_data_table_row());
981: if (keys(%existingroles) > 0) {
982: $r->print(&Apache::loncommon::start_data_table_row().'<td><br />'.
983: '<label><input type="radio" name="customroleaction" value="edit" onclick="setCustomFields();"/><b>'.
984: &mt('View/Modify existing role:').'</b></label></td>'.
985: '<td align="center"><br />'.
986: '<select name="rolename" onchange="setCustomAction('."'edit'".');">'.
1.326 raeburn 987: '<option value="" selected="selected">'.
1.324 raeburn 988: &mt('Select'));
989: foreach my $role (sort(keys(%existingroles))) {
1.326 raeburn 990: $r->print('<option value="'.$role.'">'.$role.'</option>');
1.324 raeburn 991: }
992: $r->print('</select>'.
993: '</td>'.
994: &Apache::loncommon::end_data_table_row());
995: }
996: $r->print(&Apache::loncommon::end_data_table().'<p>'.
997: '<input name="customeditor" type="submit" value="'.
998: $lt{'cre'}.'" /></p>'.
999: '</form>');
1.190 raeburn 1000: }
1.213 raeburn 1001: } else {
1.229 raeburn 1002: my $actiontext = $lt{'srad'};
1.406.2.13 raeburn 1003: my $fixeddom;
1.213 raeburn 1004: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1005: if ($crstype eq 'Community') {
1006: $actiontext = $lt{'srme'};
1007: } else {
1008: $actiontext = $lt{'srst'};
1009: }
1.406.2.5 raeburn 1010: } elsif ($env{'form.action'} eq 'accesslogs') {
1011: $actiontext = $lt{'srva'};
1.406.2.13 raeburn 1012: $fixeddom = 1;
1.406.2.7 raeburn 1013: } elsif (($env{'form.action'} eq 'singleuser') &&
1014: ($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$defdom))) {
1015: $actiontext = $lt{'srvu'};
1.406.2.14 raeburn 1016: $fixeddom = 1;
1.213 raeburn 1017: }
1.324 raeburn 1018: $r->print("<h3>$actiontext</h3>");
1.213 raeburn 1019: if ($env{'form.origform'} ne 'crtusername') {
1.406.2.5 raeburn 1020: if ($response) {
1021: $r->print("\n<div>$response</div>".
1022: '<br clear="all" />');
1023: }
1.213 raeburn 1024: }
1.406.2.13 raeburn 1025: $r->print(&entry_form($defdom,$srch,$forcenewuser,$context,$response,$crstype,$fixeddom));
1.107 www 1026: }
1.110 albertel 1027: }
1028:
1.324 raeburn 1029: sub customrole_javascript {
1030: my $js = <<"END";
1031: <script type="text/javascript">
1032: // <![CDATA[
1033:
1034: function setCustomFields() {
1035: if (document.docustom.customroleaction.length > 0) {
1036: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1037: if (document.docustom.customroleaction[i].checked) {
1038: if (document.docustom.customroleaction[i].value == 'new') {
1039: document.docustom.rolename.selectedIndex = 0;
1040: } else {
1041: document.docustom.newrolename.value = '';
1042: }
1043: }
1044: }
1045: }
1046: return;
1047: }
1048:
1049: function setCustomAction(caller) {
1050: if (document.docustom.customroleaction.length > 0) {
1051: for (var i=0; i<document.docustom.customroleaction.length; i++) {
1052: if (document.docustom.customroleaction[i].value == caller) {
1053: document.docustom.customroleaction[i].checked = true;
1054: }
1055: }
1056: }
1057: setCustomFields();
1058: return;
1059: }
1060:
1061: // ]]>
1062: </script>
1063: END
1064: return $js;
1065: }
1066:
1.160 raeburn 1067: sub entry_form {
1.406.2.5 raeburn 1068: my ($dom,$srch,$forcenewuser,$context,$responsemsg,$crstype,$fixeddom) = @_;
1.229 raeburn 1069: my ($usertype,$inexact);
1.214 raeburn 1070: if (ref($srch) eq 'HASH') {
1071: if (($srch->{'srchin'} eq 'dom') &&
1072: ($srch->{'srchby'} eq 'uname') &&
1073: ($srch->{'srchtype'} eq 'exact') &&
1074: ($srch->{'srchdomain'} ne '') &&
1075: ($srch->{'srchterm'} ne '')) {
1.353 raeburn 1076: my (%curr_rules,%got_rules);
1.214 raeburn 1077: my ($rules,$ruleorder) =
1078: &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
1.353 raeburn 1079: $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules,\%curr_rules,\%got_rules);
1.229 raeburn 1080: } else {
1081: $inexact = 1;
1.214 raeburn 1082: }
1.207 raeburn 1083: }
1.406.2.14 raeburn 1084: my ($cancreate,$noinstd);
1085: if ($env{'form.action'} eq 'accesslogs') {
1086: $noinstd = 1;
1087: } else {
1088: $cancreate =
1089: &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
1090: }
1.406.2.3 raeburn 1091: my ($userpicker,$cansearch) =
1.179 raeburn 1092: &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
1.406.2.14 raeburn 1093: 'document.crtuser',$cancreate,$usertype,$context,$fixeddom,$noinstd);
1.160 raeburn 1094: my $srchbutton = &mt('Search');
1.229 raeburn 1095: if ($env{'form.action'} eq 'singlestudent') {
1096: $srchbutton = &mt('Search and Enroll');
1.406.2.5 raeburn 1097: } elsif ($env{'form.action'} eq 'accesslogs') {
1098: $srchbutton = &mt('Search');
1.229 raeburn 1099: } elsif ($cancreate && $responsemsg ne '' && $inexact) {
1100: $srchbutton = &mt('Search or Add New User');
1101: }
1.406.2.3 raeburn 1102: my $output;
1103: if ($cansearch) {
1104: $output = <<"ENDBLOCK";
1.160 raeburn 1105: <form action="/adm/createuser" method="post" name="crtuser">
1.190 raeburn 1106: <input type="hidden" name="action" value="$env{'form.action'}" />
1.160 raeburn 1107: <input type="hidden" name="phase" value="get_user_info" />
1108: $userpicker
1.179 raeburn 1109: <input name="userrole" type="button" value="$srchbutton" onclick="javascript:validateEntry(document.crtuser)" />
1.160 raeburn 1110: </form>
1.207 raeburn 1111: ENDBLOCK
1.406.2.3 raeburn 1112: } else {
1113: $output = '<p>'.$userpicker.'</p>';
1114: }
1.406.2.7 raeburn 1115: if (($env{'form.phase'} eq '') && ($env{'form.action'} ne 'accesslogs') &&
1116: (!(($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1117: (!&Apache::lonnet::allowed('mau',$env{'request.role.domain'}))))) {
1.207 raeburn 1118: my $defdom=$env{'request.role.domain'};
1119: my $domform = &Apache::loncommon::select_dom_form($defdom,'srchdomain');
1120: my %lt=&Apache::lonlocal::texthash(
1.229 raeburn 1121: 'enro' => 'Enroll one student',
1.318 raeburn 1122: 'enrm' => 'Enroll one member',
1.229 raeburn 1123: 'admo' => 'Add/modify a single user',
1124: 'crea' => 'create new user if required',
1125: 'uskn' => "username is known",
1.207 raeburn 1126: 'crnu' => 'Create a new user',
1127: 'usr' => 'Username',
1128: 'dom' => 'in domain',
1.229 raeburn 1129: 'enrl' => 'Enroll',
1130: 'cram' => 'Create/Modify user',
1.207 raeburn 1131: );
1.229 raeburn 1132: my $sellink=&Apache::loncommon::selectstudent_link('crtusername','srchterm','srchdomain');
1133: my ($title,$buttontext,$showresponse);
1.318 raeburn 1134: if ($env{'form.action'} eq 'singlestudent') {
1135: if ($crstype eq 'Community') {
1136: $title = $lt{'enrm'};
1137: } else {
1138: $title = $lt{'enro'};
1139: }
1.229 raeburn 1140: $buttontext = $lt{'enrl'};
1141: } else {
1142: $title = $lt{'admo'};
1143: $buttontext = $lt{'cram'};
1144: }
1145: if ($cancreate) {
1146: $title .= ' <span class="LC_cusr_subheading">('.$lt{'crea'}.')</span>';
1147: } else {
1148: $title .= ' <span class="LC_cusr_subheading">('.$lt{'uskn'}.')</span>';
1149: }
1150: if ($env{'form.origform'} eq 'crtusername') {
1151: $showresponse = $responsemsg;
1152: }
1.207 raeburn 1153: $output .= <<"ENDDOCUMENT";
1.229 raeburn 1154: <br />
1.207 raeburn 1155: <form action="/adm/createuser" method="post" name="crtusername">
1156: <input type="hidden" name="action" value="$env{'form.action'}" />
1157: <input type="hidden" name="phase" value="createnewuser" />
1158: <input type="hidden" name="srchtype" value="exact" />
1.233 raeburn 1159: <input type="hidden" name="srchby" value="uname" />
1.207 raeburn 1160: <input type="hidden" name="srchin" value="dom" />
1161: <input type="hidden" name="forcenewuser" value="1" />
1162: <input type="hidden" name="origform" value="crtusername" />
1.229 raeburn 1163: <h3>$title</h3>
1164: $showresponse
1.207 raeburn 1165: <table>
1166: <tr>
1167: <td>$lt{'usr'}:</td>
1168: <td><input type="text" size="15" name="srchterm" /></td>
1169: <td> $lt{'dom'}:</td><td>$domform</td>
1.229 raeburn 1170: <td> $sellink </td>
1171: <td> <input name="userrole" type="submit" value="$buttontext" /></td>
1.207 raeburn 1172: </tr>
1173: </table>
1174: </form>
1.160 raeburn 1175: ENDDOCUMENT
1.207 raeburn 1176: }
1.160 raeburn 1177: return $output;
1178: }
1.110 albertel 1179:
1180: sub user_modification_js {
1.113 raeburn 1181: my ($pjump_def,$dc_setcourse_code,$nondc_setsection_code,$groupslist)=@_;
1182:
1.110 albertel 1183: return <<END;
1184: <script type="text/javascript" language="Javascript">
1.301 bisitz 1185: // <![CDATA[
1.314 raeburn 1186:
1.110 albertel 1187: $pjump_def
1188: $dc_setcourse_code
1189:
1190: function dateset() {
1191: eval("document.cu."+document.cu.pres_marker.value+
1192: ".value=document.cu.pres_value.value");
1.359 www 1193: modalWindow.close();
1.110 albertel 1194: }
1195:
1.113 raeburn 1196: $nondc_setsection_code
1.301 bisitz 1197: // ]]>
1.110 albertel 1198: </script>
1199: END
1.2 www 1200: }
1201:
1202: # =================================================================== Phase two
1.160 raeburn 1203: sub print_user_selection_page {
1.351 raeburn 1204: my ($r,$response,$srch,$srch_results,$srcharray,$context,$opener_elements,$crstype,$brcrum) = @_;
1.160 raeburn 1205: my @fields = ('username','domain','lastname','firstname','permanentemail');
1206: my $sortby = $env{'form.sortby'};
1207:
1208: if (!grep(/^\Q$sortby\E$/,@fields)) {
1209: $sortby = 'lastname';
1210: }
1211:
1212: my ($jsback,$elements) = &crumb_utilities();
1213:
1214: my $jscript = (<<ENDSCRIPT);
1215: <script type="text/javascript">
1.301 bisitz 1216: // <![CDATA[
1.160 raeburn 1217: function pickuser(uname,udom) {
1218: document.usersrchform.seluname.value=uname;
1219: document.usersrchform.seludom.value=udom;
1220: document.usersrchform.phase.value="userpicked";
1221: document.usersrchform.submit();
1222: }
1223:
1224: $jsback
1.301 bisitz 1225: // ]]>
1.160 raeburn 1226: </script>
1227: ENDSCRIPT
1228:
1229: my %lt=&Apache::lonlocal::texthash(
1.179 raeburn 1230: 'usrch' => "User Search to add/modify roles",
1231: 'stusrch' => "User Search to enroll student",
1.318 raeburn 1232: 'memsrch' => "User Search to enroll member",
1.406.2.5 raeburn 1233: 'srcva' => "Search for a user and view access log information",
1.406.2.7 raeburn 1234: 'usrvu' => "User Search to view user roles",
1.179 raeburn 1235: 'usel' => "Select a user to add/modify roles",
1.406.2.7 raeburn 1236: 'suvr' => "Select a user to view roles",
1.318 raeburn 1237: 'stusel' => "Select a user to enroll as a student",
1238: 'memsel' => "Select a user to enroll as a member",
1.406.2.5 raeburn 1239: 'vacsel' => "Select a user to view access log",
1.160 raeburn 1240: 'username' => "username",
1241: 'domain' => "domain",
1242: 'lastname' => "last name",
1243: 'firstname' => "first name",
1244: 'permanentemail' => "permanent e-mail",
1245: );
1.302 raeburn 1246: if ($context eq 'requestcrs') {
1247: $r->print('<div>');
1248: } else {
1.406.2.7 raeburn 1249: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$srch->{'srchdomain'});
1.351 raeburn 1250: my $helpitem;
1251: if ($env{'form.action'} eq 'singleuser') {
1252: $helpitem = 'Course_Change_Privileges';
1253: } elsif ($env{'form.action'} eq 'singlestudent') {
1254: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1255: } elsif ($context eq 'author') {
1256: $helpitem = 'Author_Change_Privileges';
1257: } elsif ($context eq 'domain') {
1258: $helpitem = 'Domain_Change_Privileges';
1.351 raeburn 1259: }
1260: push (@{$brcrum},
1261: {href => "javascript:backPage(document.usersrchform,'','')",
1262: text => $breadcrumb_text{'search'},
1263: faq => 282,
1264: bug => 'Instructor Interface',},
1265: {href => "javascript:backPage(document.usersrchform,'get_user_info','select')",
1266: text => $breadcrumb_text{'userpicked'},
1267: faq => 282,
1268: bug => 'Instructor Interface',
1269: help => $helpitem}
1270: );
1271: $r->print(&Apache::loncommon::start_page('User Management',$jscript,{bread_crumbs => $brcrum}));
1.302 raeburn 1272: if ($env{'form.action'} eq 'singleuser') {
1.406.2.7 raeburn 1273: my $readonly;
1274: if (($context eq 'domain') && (!&Apache::lonnet::allowed('mau',$srch->{'srchdomain'}))) {
1275: $readonly = 1;
1276: $r->print("<b>$lt{'usrvu'}</b><br />");
1277: } else {
1278: $r->print("<b>$lt{'usrch'}</b><br />");
1279: }
1.318 raeburn 1280: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1.406.2.7 raeburn 1281: if ($readonly) {
1282: $r->print('<h3>'.$lt{'suvr'}.'</h3>');
1283: } else {
1284: $r->print('<h3>'.$lt{'usel'}.'</h3>');
1285: }
1.302 raeburn 1286: } elsif ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1287: $r->print($jscript."<b>");
1288: if ($crstype eq 'Community') {
1289: $r->print($lt{'memsrch'});
1290: } else {
1291: $r->print($lt{'stusrch'});
1292: }
1293: $r->print("</b><br />");
1294: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,$crstype));
1295: $r->print('</form><h3>');
1296: if ($crstype eq 'Community') {
1297: $r->print($lt{'memsel'});
1298: } else {
1299: $r->print($lt{'stusel'});
1300: }
1301: $r->print('</h3>');
1.406.2.5 raeburn 1302: } elsif ($env{'form.action'} eq 'accesslogs') {
1303: $r->print("<b>$lt{'srcva'}</b><br />");
1.406.2.14 raeburn 1304: $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context,undef,undef,1));
1.406.2.5 raeburn 1305: $r->print('<h3>'.$lt{'vacsel'}.'</h3>');
1.302 raeburn 1306: }
1.179 raeburn 1307: }
1.380 bisitz 1308: $r->print('<form name="usersrchform" method="post" action="">'.
1.160 raeburn 1309: &Apache::loncommon::start_data_table()."\n".
1310: &Apache::loncommon::start_data_table_header_row()."\n".
1311: ' <th> </th>'."\n");
1312: foreach my $field (@fields) {
1313: $r->print(' <th><a href="javascript:document.usersrchform.sortby.value='.
1314: "'".$field."'".';document.usersrchform.submit();">'.
1315: $lt{$field}.'</a></th>'."\n");
1316: }
1317: $r->print(&Apache::loncommon::end_data_table_header_row());
1318:
1319: my @sorted_users = sort {
1.167 albertel 1320: lc($srch_results->{$a}->{$sortby}) cmp lc($srch_results->{$b}->{$sortby})
1.160 raeburn 1321: ||
1.167 albertel 1322: lc($srch_results->{$a}->{lastname}) cmp lc($srch_results->{$b}->{lastname})
1.160 raeburn 1323: ||
1324: lc($srch_results->{$a}->{firstname}) cmp lc($srch_results->{$b}->{firstname})
1.167 albertel 1325: ||
1326: lc($a) cmp lc($b)
1.160 raeburn 1327: } (keys(%$srch_results));
1328:
1329: foreach my $user (@sorted_users) {
1330: my ($uname,$udom) = split(/:/,$user);
1.302 raeburn 1331: my $onclick;
1332: if ($context eq 'requestcrs') {
1.314 raeburn 1333: $onclick =
1.302 raeburn 1334: 'onclick="javascript:gochoose('."'$uname','$udom',".
1335: "'$srch_results->{$user}->{firstname}',".
1336: "'$srch_results->{$user}->{lastname}',".
1337: "'$srch_results->{$user}->{permanentemail}'".');"';
1338: } else {
1.314 raeburn 1339: $onclick =
1.302 raeburn 1340: ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
1341: }
1.160 raeburn 1342: $r->print(&Apache::loncommon::start_data_table_row().
1.302 raeburn 1343: '<td><input type="button" name="seluser" value="'.&mt('Select').'" '.
1344: $onclick.' /></td>'.
1.160 raeburn 1345: '<td><tt>'.$uname.'</tt></td>'.
1346: '<td><tt>'.$udom.'</tt></td>');
1347: foreach my $field ('lastname','firstname','permanentemail') {
1348: $r->print('<td>'.$srch_results->{$user}->{$field}.'</td>');
1349: }
1350: $r->print(&Apache::loncommon::end_data_table_row());
1351: }
1352: $r->print(&Apache::loncommon::end_data_table().'<br /><br />');
1.179 raeburn 1353: if (ref($srcharray) eq 'ARRAY') {
1354: foreach my $item (@{$srcharray}) {
1355: $r->print('<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n");
1356: }
1357: }
1.160 raeburn 1358: $r->print(' <input type="hidden" name="sortby" value="'.$sortby.'" />'."\n".
1359: ' <input type="hidden" name="seluname" value="" />'."\n".
1360: ' <input type="hidden" name="seludom" value="" />'."\n".
1.179 raeburn 1361: ' <input type="hidden" name="currstate" value="select" />'."\n".
1.190 raeburn 1362: ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
1.214 raeburn 1363: ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
1.302 raeburn 1364: if ($context eq 'requestcrs') {
1365: $r->print($opener_elements.'</form></div>');
1366: } else {
1.351 raeburn 1367: $r->print($response.'</form>');
1.302 raeburn 1368: }
1.160 raeburn 1369: }
1370:
1371: sub print_user_query_page {
1.351 raeburn 1372: my ($r,$caller,$brcrum) = @_;
1.160 raeburn 1373: # FIXME - this is for a network-wide name search (similar to catalog search)
1374: # To use frames with similar behavior to catalog/portfolio search.
1375: # To be implemented.
1376: return;
1377: }
1378:
1.42 matthew 1379: sub print_user_modification_page {
1.375 raeburn 1380: my ($r,$ccuname,$ccdomain,$srch,$response,$context,$permission,$crstype,
1381: $brcrum,$showcredits) = @_;
1.185 raeburn 1382: if (($ccuname eq '') || ($ccdomain eq '')) {
1.215 raeburn 1383: my $usermsg = &mt('No username and/or domain provided.');
1384: $env{'form.phase'} = '';
1.406.2.14 raeburn 1385: &print_username_entry_form($r,$context,$usermsg,'','',$crstype,$brcrum,
1386: $permission);
1.58 www 1387: return;
1388: }
1.213 raeburn 1389: my ($form,$formname);
1390: if ($env{'form.action'} eq 'singlestudent') {
1391: $form = 'document.enrollstudent';
1392: $formname = 'enrollstudent';
1393: } else {
1394: $form = 'document.cu';
1395: $formname = 'cu';
1396: }
1.188 raeburn 1397: my %abv_auth = &auth_abbrev();
1.227 raeburn 1398: my (%rulematch,%inst_results,$newuser,%alerts,%curr_rules,%got_rules);
1.185 raeburn 1399: my $uhome=&Apache::lonnet::homeserver($ccuname,$ccdomain);
1400: if ($uhome eq 'no_host') {
1.215 raeburn 1401: my $usertype;
1402: my ($rules,$ruleorder) =
1403: &Apache::lonnet::inst_userrules($ccdomain,'username');
1404: $usertype =
1.353 raeburn 1405: &Apache::lonuserutils::check_usertype($ccdomain,$ccuname,$rules,
1.362 raeburn 1406: \%curr_rules,\%got_rules);
1.215 raeburn 1407: my $cancreate =
1408: &Apache::lonuserutils::can_create_user($ccdomain,$context,
1409: $usertype);
1410: if (!$cancreate) {
1.292 bisitz 1411: my $helplink = 'javascript:helpMenu('."'display'".')';
1.215 raeburn 1412: my %usertypetext = (
1413: official => 'institutional',
1414: unofficial => 'non-institutional',
1415: );
1416: my $response;
1417: if ($env{'form.origform'} eq 'crtusername') {
1.362 raeburn 1418: $response = '<span class="LC_warning">'.
1419: &mt('No match found for the username [_1] in LON-CAPA domain: [_2]',
1420: '<b>'.$ccuname.'</b>',$ccdomain).
1.215 raeburn 1421: '</span><br />';
1422: }
1.292 bisitz 1423: $response .= '<p class="LC_warning">'
1424: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
1.406.2.6 raeburn 1425: .' ';
1426: if ($context eq 'domain') {
1427: $response .= &mt('Please contact a [_1] for assistance.',
1428: &Apache::lonnet::plaintext('dc'));
1429: } else {
1430: $response .= &mt('Please contact the [_1]helpdesk[_2] for assistance.'
1431: ,'<a href="'.$helplink.'">','</a>');
1432: }
1433: $response .= '</p><br />';
1.215 raeburn 1434: $env{'form.phase'} = '';
1.406.2.14 raeburn 1435: &print_username_entry_form($r,$context,$response,undef,undef,$crstype,$brcrum,
1436: $permission);
1.215 raeburn 1437: return;
1438: }
1.188 raeburn 1439: $newuser = 1;
1.193 raeburn 1440: my $checkhash;
1441: my $checks = { 'username' => 1 };
1.196 raeburn 1442: $checkhash->{$ccuname.':'.$ccdomain} = { 'newuser' => $newuser };
1.193 raeburn 1443: &Apache::loncommon::user_rule_check($checkhash,$checks,
1.196 raeburn 1444: \%alerts,\%rulematch,\%inst_results,\%curr_rules,\%got_rules);
1445: if (ref($alerts{'username'}) eq 'HASH') {
1446: if (ref($alerts{'username'}{$ccdomain}) eq 'HASH') {
1447: my $domdesc =
1.193 raeburn 1448: &Apache::lonnet::domain($ccdomain,'description');
1.196 raeburn 1449: if ($alerts{'username'}{$ccdomain}{$ccuname}) {
1450: my $userchkmsg;
1451: if (ref($curr_rules{$ccdomain}) eq 'HASH') {
1452: $userchkmsg =
1453: &Apache::loncommon::instrule_disallow_msg('username',
1.193 raeburn 1454: $domdesc,1).
1455: &Apache::loncommon::user_rule_formats($ccdomain,
1456: $domdesc,$curr_rules{$ccdomain}{'username'},
1457: 'username');
1.196 raeburn 1458: }
1.215 raeburn 1459: $env{'form.phase'} = '';
1.406.2.14 raeburn 1460: &print_username_entry_form($r,$context,$userchkmsg,undef,undef,$crstype,$brcrum,
1461: $permission);
1.196 raeburn 1462: return;
1.215 raeburn 1463: }
1.193 raeburn 1464: }
1.185 raeburn 1465: }
1.187 raeburn 1466: } else {
1.188 raeburn 1467: $newuser = 0;
1.185 raeburn 1468: }
1.160 raeburn 1469: if ($response) {
1.215 raeburn 1470: $response = '<br />'.$response;
1.160 raeburn 1471: }
1.149 raeburn 1472:
1.52 matthew 1473: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
1.88 raeburn 1474: my $dc_setcourse_code = '';
1.119 raeburn 1475: my $nondc_setsection_code = '';
1.112 albertel 1476: my %loaditem;
1.114 albertel 1477:
1.216 raeburn 1478: my $groupslist = &Apache::lonuserutils::get_groupslist();
1.88 raeburn 1479:
1.406.2.20.2. (raeburn 1480:): my $js = &validation_javascript($context,$ccdomain,$pjump_def,
1481:): $crstype,$groupslist,$newuser,
1482:): $formname,\%loaditem,$permission);
1.406.2.7 raeburn 1483: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$ccdomain);
1.224 raeburn 1484: my $helpitem = 'Course_Change_Privileges';
1485: if ($env{'form.action'} eq 'singlestudent') {
1486: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 1487: } elsif ($context eq 'author') {
1488: $helpitem = 'Author_Change_Privileges';
1489: } elsif ($context eq 'domain') {
1490: $helpitem = 'Domain_Change_Privileges';
1.406.2.20.2. (raeburn 1491:): $js .= &set_custom_js();
1.224 raeburn 1492: }
1.351 raeburn 1493: push (@{$brcrum},
1494: {href => "javascript:backPage($form)",
1495: text => $breadcrumb_text{'search'},
1496: faq => 282,
1497: bug => 'Instructor Interface',});
1498: if ($env{'form.phase'} eq 'userpicked') {
1499: push(@{$brcrum},
1500: {href => "javascript:backPage($form,'get_user_info','select')",
1501: text => $breadcrumb_text{'userpicked'},
1502: faq => 282,
1503: bug => 'Instructor Interface',});
1504: }
1505: push(@{$brcrum},
1506: {href => "javascript:backPage($form,'$env{'form.phase'}','modify')",
1507: text => $breadcrumb_text{'modify'},
1508: faq => 282,
1509: bug => 'Instructor Interface',
1510: help => $helpitem});
1511: my $args = {'add_entries' => \%loaditem,
1512: 'bread_crumbs' => $brcrum,
1513: 'bread_crumbs_component' => 'User Management'};
1514: if ($env{'form.popup'}) {
1515: $args->{'no_nav_bar'} = 1;
1.406.2.20.2. (raeburn 1516:): $args->{'add_modal'} = 1;
1.351 raeburn 1517: }
1.406.2.20.2. (raeburn 1518:): if (($context eq 'domain') && ($env{'request.role.domain'} eq $ccdomain)) {
1519:): my @toggles;
1520:): if (&Apache::lonnet::allowed('cau',$ccdomain)) {
1521:): my ($isadv,$isauthor) =
1522:): &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1523:): unless ($isauthor) {
1524:): push(@toggles,'requestauthor');
1525:): }
1526:): push(@toggles,('webdav','editors','archive'));
1527:): }
1528:): if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1529:): push(@toggles,('aboutme','blog','portfolio','portaccess','timezone'));
1530:): }
1531:): if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1532:): push(@toggles,('official','unofficial','community','textbook'));
1533:): }
1534:): if (@toggles) {
1535:): my $onload;
1536:): foreach my $item (@toggles) {
1537:): $onload .= "toggleCustom(document.cu,'customtext_$item','custom$item');";
1538:): }
1539:): $args->{'add_entries'} = {
1540:): 'onload' => $onload,
1541:): };
1542:): }
1543:): }
1.351 raeburn 1544: my $start_page =
1545: &Apache::loncommon::start_page('User Management',$js,$args);
1.3 www 1546:
1.25 matthew 1547: my $forminfo =<<"ENDFORMINFO";
1.216 raeburn 1548: <form action="/adm/createuser" method="post" name="$formname">
1.190 raeburn 1549: <input type="hidden" name="phase" value="update_user_data" />
1.188 raeburn 1550: <input type="hidden" name="ccuname" value="$ccuname" />
1551: <input type="hidden" name="ccdomain" value="$ccdomain" />
1.157 albertel 1552: <input type="hidden" name="pres_value" value="" />
1553: <input type="hidden" name="pres_type" value="" />
1554: <input type="hidden" name="pres_marker" value="" />
1.25 matthew 1555: ENDFORMINFO
1.375 raeburn 1556: my (%inccourses,$roledom,$defaultcredits);
1.329 raeburn 1557: if ($context eq 'course') {
1558: $inccourses{$env{'request.course.id'}}=1;
1559: $roledom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.375 raeburn 1560: if ($showcredits) {
1561: $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1562: }
1.329 raeburn 1563: } elsif ($context eq 'author') {
1564: $roledom = $env{'request.role.domain'};
1565: } elsif ($context eq 'domain') {
1566: foreach my $key (keys(%env)) {
1567: $roledom = $env{'request.role.domain'};
1568: if ($key=~/^user\.priv\.cm\.\/($roledom)\/($match_username)/) {
1569: $inccourses{$1.'_'.$2}=1;
1570: }
1571: }
1572: } else {
1573: foreach my $key (keys(%env)) {
1574: if ($key=~/^user\.priv\.cm\.\/($match_domain)\/($match_username)/) {
1575: $inccourses{$1.'_'.$2}=1;
1576: }
1.2 www 1577: }
1.24 matthew 1578: }
1.389 bisitz 1579: my $title = '';
1.406.2.20.2. (raeburn 1580:): my $need_quota_js;
1.216 raeburn 1581: if ($newuser) {
1.406.2.9 raeburn 1582: my ($portfolioform,$domroleform);
1.267 raeburn 1583: if ((&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) ||
1584: (&Apache::lonnet::allowed('mut',$env{'request.role.domain'}))) {
1585: # Current user has quota or user tools modification privileges
1.406.2.20.2. (raeburn 1586:): $portfolioform = '<br /><h3>'.
1587:): &mt('User Tools').
1588:): '</h3>'."\n".
1589:): &Apache::loncommon::start_data_table();
1590:): if (&Apache::lonnet::allowed('mut',$ccdomain)) {
1591:): $portfolioform .= &build_tools_display($ccuname,$ccdomain,'tools');
1592:): }
1593:): if (&Apache::lonnet::allowed('mpq',$ccdomain)) {
1594:): $portfolioform .= &user_quotas($ccuname,$ccdomain,'portfolio');
1595:): $need_quota_js = 1;
1596:): }
1597:): $portfolioform .= &Apache::loncommon::end_data_table();
1.134 raeburn 1598: }
1.383 raeburn 1599: if ((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) &&
1600: ($ccdomain eq $env{'request.role.domain'})) {
1.406.2.20.2. (raeburn 1601:): $domroleform = &domainrole_req($ccuname,$ccdomain).
1602:): &authoring_defaults($ccuname,$ccdomain);
1603:): $need_quota_js = 1;
1604:): }
1605:): my $readonly;
1606:): unless ($permission->{'cusr'}) {
1607:): $readonly = 1;
1.362 raeburn 1608: }
1.406.2.20.2. (raeburn 1609:): &initialize_authen_forms($ccdomain,$formname,'','',$readonly);
1.188 raeburn 1610: my %lt=&Apache::lonlocal::texthash(
1611: 'lg' => 'Login Data',
1.190 raeburn 1612: 'hs' => "Home Server",
1.188 raeburn 1613: );
1.185 raeburn 1614: $r->print(<<ENDTITLE);
1.110 albertel 1615: $start_page
1.160 raeburn 1616: $response
1.25 matthew 1617: $forminfo
1.31 matthew 1618: <script type="text/javascript" language="Javascript">
1.301 bisitz 1619: // <![CDATA[
1.20 harris41 1620: $loginscript
1.301 bisitz 1621: // ]]>
1.31 matthew 1622: </script>
1.20 harris41 1623: <input type='hidden' name='makeuser' value='1' />
1.185 raeburn 1624: ENDTITLE
1.213 raeburn 1625: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1626: if ($crstype eq 'Community') {
1.389 bisitz 1627: $title = &mt('Create New User [_1] in domain [_2] as a member',
1628: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1629: } else {
1.389 bisitz 1630: $title = &mt('Create New User [_1] in domain [_2] as a student',
1631: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1632: }
1.389 bisitz 1633: } else {
1634: $title = &mt('Create New User [_1] in domain [_2]',
1635: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.213 raeburn 1636: }
1.389 bisitz 1637: $r->print('<h2>'.$title.'</h2>'."\n");
1638: $r->print('<div class="LC_left_float">');
1.393 raeburn 1639: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1.406.2.20.2. (raeburn 1640:): $inst_results{$ccuname.':'.$ccdomain},$readonly));
1.393 raeburn 1641: # Option to disable student/employee ID conflict checking not offerred for new users.
1.187 raeburn 1642: my ($home_server_pick,$numlib) =
1643: &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
1644: 'default','hide');
1645: if ($numlib > 1) {
1646: $r->print("
1.185 raeburn 1647: <br />
1.187 raeburn 1648: $lt{'hs'}: $home_server_pick
1649: <br />");
1650: } else {
1651: $r->print($home_server_pick);
1652: }
1.304 raeburn 1653: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.362 raeburn 1654: $r->print('<br /><h3>'.
1.406.2.20.2. (raeburn 1655:): &mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'.
1.304 raeburn 1656: &Apache::loncommon::start_data_table().
1657: &build_tools_display($ccuname,$ccdomain,
1658: 'requestcourses').
1659: &Apache::loncommon::end_data_table());
1660: }
1.188 raeburn 1661: $r->print('</div>'."\n".'<div class="LC_left_float"><h3>'.
1662: $lt{'lg'}.'</h3>');
1.185 raeburn 1663: my ($fixedauth,$varauth,$authmsg);
1.193 raeburn 1664: if (ref($rulematch{$ccuname.':'.$ccdomain}) eq 'HASH') {
1665: my $matchedrule = $rulematch{$ccuname.':'.$ccdomain}{'username'};
1666: my ($rules,$ruleorder) =
1667: &Apache::lonnet::inst_userrules($ccdomain,'username');
1.185 raeburn 1668: if (ref($rules) eq 'HASH') {
1.193 raeburn 1669: if (ref($rules->{$matchedrule}) eq 'HASH') {
1670: my $authtype = $rules->{$matchedrule}{'authtype'};
1.185 raeburn 1671: if ($authtype !~ /^(krb4|krb5|int|fsys|loc)$/) {
1.190 raeburn 1672: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.275 raeburn 1673: } else {
1.193 raeburn 1674: my $authparm = $rules->{$matchedrule}{'authparm'};
1.273 raeburn 1675: $authmsg = $rules->{$matchedrule}{'authmsg'};
1.185 raeburn 1676: if ($authtype =~ /^krb(4|5)$/) {
1677: my $ver = $1;
1678: if ($authparm ne '') {
1679: $fixedauth = <<"KERB";
1680: <input type="hidden" name="login" value="krb" />
1681: <input type="hidden" name="krbver" value="$ver" />
1682: <input type="hidden" name="krbarg" value="$authparm" />
1683: KERB
1684: }
1685: } else {
1686: $fixedauth =
1687: '<input type="hidden" name="login" value="'.$authtype.'" />'."\n";
1.193 raeburn 1688: if ($rules->{$matchedrule}{'authparmfixed'}) {
1.185 raeburn 1689: $fixedauth .=
1690: '<input type="hidden" name="'.$authtype.'arg" value="'.$authparm.'" />'."\n";
1691: } else {
1.273 raeburn 1692: if ($authtype eq 'int') {
1693: $varauth = '<br />'.
1.301 bisitz 1694: &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 1695: } elsif ($authtype eq 'loc') {
1696: $varauth = '<br />'.
1697: &mt('[_1] Local Authentication with argument [_2]','','<input type="text" name="'.$authtype.'arg" value="" />')."\n";
1698: } else {
1699: $varauth =
1.185 raeburn 1700: '<input type="text" name="'.$authtype.'arg" value="" />'."\n";
1.273 raeburn 1701: }
1.185 raeburn 1702: }
1703: }
1704: }
1705: } else {
1.190 raeburn 1706: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.185 raeburn 1707: }
1708: }
1709: if ($authmsg) {
1710: $r->print(<<ENDAUTH);
1711: $fixedauth
1712: $authmsg
1713: $varauth
1714: ENDAUTH
1715: }
1716: } else {
1.190 raeburn 1717: $r->print(&Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc));
1.187 raeburn 1718: }
1.406.2.9 raeburn 1719: $r->print($portfolioform.$domroleform);
1.215 raeburn 1720: if ($env{'form.action'} eq 'singlestudent') {
1721: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1722: $permission,$crstype,$ccuname,
1723: $ccdomain,$showcredits));
1.215 raeburn 1724: }
1725: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.216 raeburn 1726: } else { # user already exists
1.389 bisitz 1727: $r->print($start_page.$forminfo);
1.213 raeburn 1728: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1729: if ($crstype eq 'Community') {
1.389 bisitz 1730: $title = &mt('Enroll one member: [_1] in domain [_2]',
1731: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1732: } else {
1.389 bisitz 1733: $title = &mt('Enroll one student: [_1] in domain [_2]',
1734: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.318 raeburn 1735: }
1.213 raeburn 1736: } else {
1.406.2.6 raeburn 1737: if ($permission->{'cusr'}) {
1738: $title = &mt('Modify existing user: [_1] in domain [_2]',
1739: '"'.$ccuname.'"','"'.$ccdomain.'"');
1740: } else {
1741: $title = &mt('Existing user: [_1] in domain [_2]',
1.389 bisitz 1742: '"'.$ccuname.'"','"'.$ccdomain.'"');
1.406.2.6 raeburn 1743: }
1.213 raeburn 1744: }
1.389 bisitz 1745: $r->print('<h2>'.$title.'</h2>'."\n");
1746: $r->print('<div class="LC_left_float">');
1.393 raeburn 1747: $r->print(&personal_data_display($ccuname,$ccdomain,$newuser,$context,
1748: $inst_results{$ccuname.':'.$ccdomain}));
1.406.2.6 raeburn 1749: if ((&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) ||
1750: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) {
1.406.2.20.2. (raeburn 1751:): $r->print('<br /><h3>'.&mt('Can Request Creation of Courses/Communities in this Domain?').'</h3>'."\n".
1.300 raeburn 1752: &Apache::loncommon::start_data_table());
1.314 raeburn 1753: if ($env{'request.role.domain'} eq $ccdomain) {
1.300 raeburn 1754: $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
1755: } else {
1756: $r->print(&coursereq_externaluser($ccuname,$ccdomain,
1757: $env{'request.role.domain'}));
1758: }
1759: $r->print(&Apache::loncommon::end_data_table());
1.275 raeburn 1760: }
1.199 raeburn 1761: $r->print('</div>');
1.406.2.20.2. (raeburn 1762:): my @order = ('auth','quota','tools','requestauthor','authordefaults');
1.362 raeburn 1763: my %user_text;
1764: my ($isadv,$isauthor) =
1.406.2.6 raeburn 1765: &Apache::lonnet::is_advanced_user($ccdomain,$ccuname);
1.406.2.20.2. (raeburn 1766:): if (((&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) ||
1.406.2.6 raeburn 1767: (&Apache::lonnet::allowed('udp',$env{'request.role.domain'}))) &&
1.406.2.20.2. (raeburn 1768:): ($env{'request.role.domain'} eq $ccdomain)) {
1769:): if (!$isauthor) {
1770:): $user_text{'requestauthor'} = &domainrole_req($ccuname,$ccdomain);
1771:): }
1772:): $user_text{'authordefaults'} = &authoring_defaults($ccuname,$ccdomain);
1773:): if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
1774:): $need_quota_js = 1;
1775:): }
1.362 raeburn 1776: }
1.406.2.17 raeburn 1777: $user_text{'auth'} = &user_authentication($ccuname,$ccdomain,$formname,$crstype,$permission);
1.267 raeburn 1778: if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1.406.2.6 raeburn 1779: (&Apache::lonnet::allowed('mut',$ccdomain)) ||
1780: (&Apache::lonnet::allowed('udp',$ccdomain))) {
1.406.2.20.2. (raeburn 1781:): $user_text{'quota'} = '<br /><h3>'.&mt('User Tools').'</h3>'."\n".
1782:): &Apache::loncommon::start_data_table();
1783:): if ((&Apache::lonnet::allowed('mut',$ccdomain)) ||
1784:): (&Apache::lonnet::allowed('udp',$ccdomain))) {
1785:): $user_text{'quota'} .= &build_tools_display($ccuname,$ccdomain,'tools');
1786:): }
1.188 raeburn 1787: # Current user has quota modification privileges
1.406.2.20.2. (raeburn 1788:): if ((&Apache::lonnet::allowed('mpq',$ccdomain)) ||
1789:): (&Apache::lonnet::allowed('udp',$ccdomain))) {
1790:): $user_text{'quota'} .= &user_quotas($ccuname,$ccdomain,'portfolio');
1791:): $need_quota_js = 1;
1792:): }
1793:): $user_text{'quota'} .= &Apache::loncommon::end_data_table();
1.267 raeburn 1794: }
1795: if (!&Apache::lonnet::allowed('mpq',$ccdomain)) {
1796: if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
1797: my %lt=&Apache::lonlocal::texthash(
1.406.2.20.2. (raeburn 1798:): 'dska' => "Disk quotas for user's portfolio",
1799:): 'youd' => "You do not have privileges to modify the portfolio quota for this user.",
1.267 raeburn 1800: 'ichr' => "If a change is required, contact a domain coordinator for the domain",
1801: );
1.362 raeburn 1802: $user_text{'quota'} = <<ENDNOPORTPRIV;
1.188 raeburn 1803: <h3>$lt{'dska'}</h3>
1804: $lt{'youd'} $lt{'ichr'}: $ccdomain
1805: ENDNOPORTPRIV
1.267 raeburn 1806: }
1807: }
1808: if (!&Apache::lonnet::allowed('mut',$ccdomain)) {
1809: if (&Apache::lonnet::allowed('mut',$env{'request.role.domain'})) {
1810: my %lt=&Apache::lonlocal::texthash(
1811: 'utav' => "User Tools Availability",
1.406.2.20.2. (raeburn 1812:): 'yodo' => "You do not have privileges to modify Portfolio, Blog, Personal Information Page, or Time Zone settings for this user.",
1.267 raeburn 1813: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
1814: );
1.362 raeburn 1815: $user_text{'tools'} = <<ENDNOTOOLSPRIV;
1.267 raeburn 1816: <h3>$lt{'utav'}</h3>
1817: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1818: ENDNOTOOLSPRIV
1819: }
1.188 raeburn 1820: }
1.362 raeburn 1821: my $gotdiv = 0;
1822: foreach my $item (@order) {
1823: if ($user_text{$item} ne '') {
1824: unless ($gotdiv) {
1825: $r->print('<div class="LC_left_float">');
1826: $gotdiv = 1;
1827: }
1828: $r->print('<br />'.$user_text{$item});
1829: }
1830: }
1831: if ($env{'form.action'} eq 'singlestudent') {
1832: unless ($gotdiv) {
1833: $r->print('<div class="LC_left_float">');
1.213 raeburn 1834: }
1.375 raeburn 1835: my $credits;
1836: if ($showcredits) {
1837: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1838: if ($credits eq '') {
1839: $credits = $defaultcredits;
1840: }
1841: }
1.374 raeburn 1842: $r->print(&date_sections_select($context,$newuser,$formname,
1.375 raeburn 1843: $permission,$crstype,$ccuname,
1844: $ccdomain,$showcredits));
1.374 raeburn 1845: }
1.362 raeburn 1846: if ($gotdiv) {
1847: $r->print('</div><div class="LC_clear_float_footer"></div>');
1.188 raeburn 1848: }
1.406.2.6 raeburn 1849: my $statuses;
1850: if (($context eq 'domain') && (&Apache::lonnet::allowed('udp',$ccdomain)) &&
1851: (!&Apache::lonnet::allowed('mau',$ccdomain))) {
1852: $statuses = ['active'];
1853: } elsif (($context eq 'course') && ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
1854: ($env{'request.course.sec'} &&
1855: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'})))) {
1856: $statuses = ['active'];
1857: }
1.217 raeburn 1858: if ($env{'form.action'} ne 'singlestudent') {
1.329 raeburn 1859: &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses,$context,
1.406.2.6 raeburn 1860: $roledom,$crstype,$showcredits,$statuses);
1.217 raeburn 1861: }
1.25 matthew 1862: } ## End of new user/old user logic
1.218 raeburn 1863: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1864: my $btntxt;
1865: if ($crstype eq 'Community') {
1866: $btntxt = &mt('Enroll Member');
1867: } else {
1868: $btntxt = &mt('Enroll Student');
1869: }
1870: $r->print('<br /><input type="button" value="'.$btntxt.'" onclick="setSections(this.form)" />'."\n");
1.406.2.6 raeburn 1871: } elsif ($permission->{'cusr'}) {
1.393 raeburn 1872: $r->print('<div class="LC_left_float">'.
1873: '<fieldset><legend>'.&mt('Add Roles').'</legend>');
1.218 raeburn 1874: my $addrolesdisplay = 0;
1875: if ($context eq 'domain' || $context eq 'author') {
1876: $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
1877: }
1878: if ($context eq 'domain') {
1.357 raeburn 1879: my $add_domainroles = &new_domain_roles($r,$ccdomain);
1.218 raeburn 1880: if (!$addrolesdisplay) {
1881: $addrolesdisplay = $add_domainroles;
1.2 www 1882: }
1.375 raeburn 1883: $r->print(&course_level_dc($env{'request.role.domain'},$showcredits));
1.393 raeburn 1884: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1885: '<br /><input type="button" value="'.&mt('Save').'" onclick="setCourse()" />'."\n");
1.218 raeburn 1886: } elsif ($context eq 'author') {
1887: if ($addrolesdisplay) {
1.393 raeburn 1888: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1889: '<br /><input type="button" value="'.&mt('Save').'"');
1.218 raeburn 1890: if ($newuser) {
1.301 bisitz 1891: $r->print(' onclick="auth_check()" \>'."\n");
1.218 raeburn 1892: } else {
1.406.2.20.2. (raeburn 1893:): $r->print(' onclick="this.form.submit()" \>'."\n");
1.218 raeburn 1894: }
1.188 raeburn 1895: } else {
1.393 raeburn 1896: $r->print('</fieldset></div>'.
1897: '<div class="LC_clear_float_footer"></div>'.
1898: '<br /><a href="javascript:backPage(document.cu)">'.
1.218 raeburn 1899: &mt('Back to previous page').'</a>');
1.188 raeburn 1900: }
1901: } else {
1.375 raeburn 1902: $r->print(&course_level_table(\%inccourses,$showcredits,$defaultcredits));
1.393 raeburn 1903: $r->print('</fieldset></div><div class="LC_clear_float_footer"></div>'.
1904: '<br /><input type="button" value="'.&mt('Save').'" onclick="setSections(this.form)" />'."\n");
1.188 raeburn 1905: }
1.88 raeburn 1906: }
1.188 raeburn 1907: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
1.179 raeburn 1908: $r->print('<input type="hidden" name="currstate" value="" />');
1.393 raeburn 1909: $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" /></form><br /><br />');
1.406.2.20.2. (raeburn 1910:): if ($need_quota_js) {
1911:): $r->print(&user_quota_js());
1912:): }
1.218 raeburn 1913: return;
1.2 www 1914: }
1.1 www 1915:
1.213 raeburn 1916: sub singleuser_breadcrumb {
1.406.2.7 raeburn 1917: my ($crstype,$context,$domain) = @_;
1.213 raeburn 1918: my %breadcrumb_text;
1919: if ($env{'form.action'} eq 'singlestudent') {
1.318 raeburn 1920: if ($crstype eq 'Community') {
1921: $breadcrumb_text{'search'} = 'Enroll a member';
1922: } else {
1923: $breadcrumb_text{'search'} = 'Enroll a student';
1924: }
1.406.2.7 raeburn 1925: $breadcrumb_text{'userpicked'} = 'Select a user';
1926: $breadcrumb_text{'modify'} = 'Set section/dates';
1.406.2.5 raeburn 1927: } elsif ($env{'form.action'} eq 'accesslogs') {
1928: $breadcrumb_text{'search'} = 'View access logs for a user';
1.406.2.7 raeburn 1929: $breadcrumb_text{'userpicked'} = 'Select a user';
1930: $breadcrumb_text{'activity'} = 'Activity';
1931: } elsif (($env{'form.action'} eq 'singleuser') && ($context eq 'domain') &&
1932: (!&Apache::lonnet::allowed('mau',$domain))) {
1933: $breadcrumb_text{'search'} = "View user's roles";
1934: $breadcrumb_text{'userpicked'} = 'Select a user';
1935: $breadcrumb_text{'modify'} = 'User roles';
1.213 raeburn 1936: } else {
1.229 raeburn 1937: $breadcrumb_text{'search'} = 'Create/modify a user';
1.406.2.7 raeburn 1938: $breadcrumb_text{'userpicked'} = 'Select a user';
1939: $breadcrumb_text{'modify'} = 'Set user role';
1.213 raeburn 1940: }
1941: return %breadcrumb_text;
1942: }
1943:
1944: sub date_sections_select {
1.375 raeburn 1945: my ($context,$newuser,$formname,$permission,$crstype,$ccuname,$ccdomain,
1946: $showcredits) = @_;
1947: my $credits;
1948: if ($showcredits) {
1949: my $defaultcredits = &Apache::lonuserutils::get_defaultcredits();
1950: $credits = &get_user_credits($ccuname,$ccdomain,$defaultcredits);
1951: if ($credits eq '') {
1952: $credits = $defaultcredits;
1953: }
1954: }
1.213 raeburn 1955: my $cid = $env{'request.course.id'};
1956: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity($cid);
1957: my $date_table = '<h3>'.&mt('Starting and Ending Dates').'</h3>'."\n".
1958: &Apache::lonuserutils::date_setting_table(undef,undef,$context,
1959: undef,$formname,$permission);
1960: my $rowtitle = 'Section';
1.375 raeburn 1961: my $secbox = '<h3>'.&mt('Section and Credits').'</h3>'."\n".
1.213 raeburn 1962: &Apache::lonuserutils::section_picker($cdom,$cnum,'st',$rowtitle,
1.375 raeburn 1963: $permission,$context,'',$crstype,
1964: $showcredits,$credits);
1.213 raeburn 1965: my $output = $date_table.$secbox;
1966: return $output;
1967: }
1968:
1.216 raeburn 1969: sub validation_javascript {
1.375 raeburn 1970: my ($context,$ccdomain,$pjump_def,$crstype,$groupslist,$newuser,$formname,
1.406.2.20.2. (raeburn 1971:): $loaditem,$permission) = @_;
1.216 raeburn 1972: my $dc_setcourse_code = '';
1973: my $nondc_setsection_code = '';
1974: if ($context eq 'domain') {
1.406.2.20.2. (raeburn 1975:): if ((ref($permission) eq 'HASH') && ($permission->{'cusr'})) {
1976:): my $dcdom = $env{'request.role.domain'};
1977:): $loaditem->{'onload'} = "document.cu.coursedesc.value='';";
1978:): $dc_setcourse_code =
1979:): &Apache::lonuserutils::dc_setcourse_js('cu','singleuser',$context);
1980:): }
1.216 raeburn 1981: } else {
1.227 raeburn 1982: my $checkauth;
1983: if (($newuser) || (&Apache::lonnet::allowed('mau',$ccdomain))) {
1984: $checkauth = 1;
1985: }
1986: if ($context eq 'course') {
1987: $nondc_setsection_code =
1988: &Apache::lonuserutils::setsections_javascript($formname,$groupslist,
1.375 raeburn 1989: undef,$checkauth,
1990: $crstype);
1.227 raeburn 1991: }
1992: if ($checkauth) {
1993: $nondc_setsection_code .=
1994: &Apache::lonuserutils::verify_authen($formname,$context);
1995: }
1.216 raeburn 1996: }
1997: my $js = &user_modification_js($pjump_def,$dc_setcourse_code,
1998: $nondc_setsection_code,$groupslist);
1999: my ($jsback,$elements) = &crumb_utilities();
2000: $js .= "\n".
1.301 bisitz 2001: '<script type="text/javascript">'."\n".
2002: '// <![CDATA['."\n".
2003: $jsback."\n".
2004: '// ]]>'."\n".
2005: '</script>'."\n";
1.216 raeburn 2006: return $js;
2007: }
2008:
1.217 raeburn 2009: sub display_existing_roles {
1.375 raeburn 2010: my ($r,$ccuname,$ccdomain,$inccourses,$context,$roledom,$crstype,
1.406.2.6 raeburn 2011: $showcredits,$statuses) = @_;
1.329 raeburn 2012: my $now=time;
1.406.2.6 raeburn 2013: my $showall = 1;
2014: my ($showexpired,$showactive);
2015: if ((ref($statuses) eq 'ARRAY') && (@{$statuses} > 0)) {
2016: $showall = 0;
2017: if (grep(/^expired$/,@{$statuses})) {
2018: $showexpired = 1;
2019: }
2020: if (grep(/^active$/,@{$statuses})) {
2021: $showactive = 1;
2022: }
2023: if ($showexpired && $showactive) {
2024: $showall = 1;
2025: }
2026: }
1.329 raeburn 2027: my %lt=&Apache::lonlocal::texthash(
1.217 raeburn 2028: 'rer' => "Existing Roles",
2029: 'rev' => "Revoke",
2030: 'del' => "Delete",
2031: 'ren' => "Re-Enable",
2032: 'rol' => "Role",
2033: 'ext' => "Extent",
1.375 raeburn 2034: 'crd' => "Credits",
1.217 raeburn 2035: 'sta' => "Start",
2036: 'end' => "End",
2037: );
1.329 raeburn 2038: my (%rolesdump,%roletext,%sortrole,%roleclass,%rolepriv);
2039: if ($context eq 'course' || $context eq 'author') {
2040: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
2041: my %roleshash =
2042: &Apache::lonnet::get_my_roles($ccuname,$ccdomain,'userroles',
2043: ['active','previous','future'],\@roles,$roledom,1);
2044: foreach my $key (keys(%roleshash)) {
2045: my ($start,$end) = split(':',$roleshash{$key});
2046: next if ($start eq '-1' || $end eq '-1');
2047: my ($rnum,$rdom,$role,$sec) = split(':',$key);
2048: if ($context eq 'course') {
2049: next unless (($rnum eq $env{'course.'.$env{'request.course.id'}.'.num'})
2050: && ($rdom eq $env{'course.'.$env{'request.course.id'}.'.domain'}));
2051: } elsif ($context eq 'author') {
1.406.2.20.2. (raeburn 2052:): if ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2053:): my ($audom,$auname) = ($1,$2);
2054:): next unless (($rnum eq $auname) && ($rdom eq $audom));
2055:): } else {
2056:): next unless (($rnum eq $env{'user.name'}) && ($rdom eq $env{'request.role.domain'}));
2057:): }
1.329 raeburn 2058: }
2059: my ($newkey,$newvalue,$newrole);
2060: $newkey = '/'.$rdom.'/'.$rnum;
2061: if ($sec ne '') {
2062: $newkey .= '/'.$sec;
2063: }
2064: $newvalue = $role;
2065: if ($role =~ /^cr/) {
2066: $newrole = 'cr';
2067: } else {
2068: $newrole = $role;
2069: }
2070: $newkey .= '_'.$newrole;
2071: if ($start ne '' && $end ne '') {
2072: $newvalue .= '_'.$end.'_'.$start;
1.335 raeburn 2073: } elsif ($end ne '') {
2074: $newvalue .= '_'.$end;
1.329 raeburn 2075: }
2076: $rolesdump{$newkey} = $newvalue;
2077: }
2078: } else {
1.360 raeburn 2079: %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
1.329 raeburn 2080: }
2081: # Build up table of user roles to allow revocation and re-enabling of roles.
2082: my ($tmp) = keys(%rolesdump);
2083: return if ($tmp =~ /^(con_lost|error)/i);
2084: foreach my $area (sort { my $a1=join('_',(split('_',$a))[1,0]);
2085: my $b1=join('_',(split('_',$b))[1,0]);
2086: return $a1 cmp $b1;
2087: } keys(%rolesdump)) {
2088: next if ($area =~ /^rolesdef/);
2089: my $envkey=$area;
2090: my $role = $rolesdump{$area};
2091: my $thisrole=$area;
2092: $area =~ s/\_\w\w$//;
2093: my ($role_code,$role_end_time,$role_start_time) =
2094: split(/_/,$role);
1.406.2.6 raeburn 2095: my $active=1;
2096: $active=0 if (($role_end_time) && ($now>$role_end_time));
2097: if ($active) {
2098: next unless($showall || $showactive);
2099: } else {
2100: next unless($showall || $showexpired);
2101: }
1.217 raeburn 2102: # Is this a custom role? Get role owner and title.
1.329 raeburn 2103: my ($croleudom,$croleuname,$croletitle)=
2104: ($role_code=~m{^cr/($match_domain)/($match_username)/(\w+)$});
2105: my $allowed=0;
2106: my $delallowed=0;
2107: my $sortkey=$role_code;
2108: my $class='Unknown';
1.375 raeburn 2109: my $credits='';
1.406.2.6 raeburn 2110: my $csec;
1.406.2.7 raeburn 2111: if ($area =~ m{^/($match_domain)/($match_courseid)}) {
1.329 raeburn 2112: $class='Course';
2113: my ($coursedom,$coursedir) = ($1,$2);
2114: my $cid = $1.'_'.$2;
2115: # $1.'_'.$2 is the course id (eg. 103_12345abcef103l3).
1.406.2.7 raeburn 2116: next if ($envkey =~ m{^/$match_domain/$match_courseid/[A-Za-z0-9]+_gr$});
1.329 raeburn 2117: my %coursedata=
2118: &Apache::lonnet::coursedescription($cid);
2119: if ($coursedir =~ /^$match_community$/) {
2120: $class='Community';
2121: }
2122: $sortkey.="\0$coursedom";
2123: my $carea;
2124: if (defined($coursedata{'description'})) {
2125: $carea=$coursedata{'description'}.
2126: '<br />'.&mt('Domain').': '.$coursedom.(' 'x8).
2127: &Apache::loncommon::syllabuswrapper(&mt('Syllabus'),$coursedir,$coursedom);
2128: $sortkey.="\0".$coursedata{'description'};
2129: } else {
2130: if ($class eq 'Community') {
2131: $carea=&mt('Unavailable community').': '.$area;
2132: $sortkey.="\0".&mt('Unavailable community').': '.$area;
1.217 raeburn 2133: } else {
2134: $carea=&mt('Unavailable course').': '.$area;
2135: $sortkey.="\0".&mt('Unavailable course').': '.$area;
2136: }
1.329 raeburn 2137: }
2138: $sortkey.="\0$coursedir";
2139: $inccourses->{$cid}=1;
1.375 raeburn 2140: if (($showcredits) && ($class eq 'Course') && ($role_code eq 'st')) {
2141: my $defaultcredits = $coursedata{'internal.defaultcredits'};
2142: $credits =
2143: &get_user_credits($ccuname,$ccdomain,$defaultcredits,
2144: $coursedom,$coursedir);
2145: if ($credits eq '') {
2146: $credits = $defaultcredits;
2147: }
2148: }
1.329 raeburn 2149: if ((&Apache::lonnet::allowed('c'.$role_code,$coursedom.'/'.$coursedir)) ||
2150: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2151: $allowed=1;
2152: }
2153: unless ($allowed) {
1.365 raeburn 2154: my $isowner = &Apache::lonuserutils::is_courseowner($cid,$coursedata{'internal.courseowner'});
1.329 raeburn 2155: if ($isowner) {
2156: if (($role_code eq 'co') && ($class eq 'Community')) {
2157: $allowed = 1;
2158: } elsif (($role_code eq 'cc') && ($class eq 'Course')) {
2159: $allowed = 1;
2160: }
1.217 raeburn 2161: }
1.329 raeburn 2162: }
2163: if ((&Apache::lonnet::allowed('dro',$coursedom)) ||
2164: (&Apache::lonnet::allowed('dro',$ccdomain))) {
2165: $delallowed=1;
2166: }
1.217 raeburn 2167: # - custom role. Needs more info, too
1.329 raeburn 2168: if ($croletitle) {
2169: if (&Apache::lonnet::allowed('ccr',$coursedom.'/'.$coursedir)) {
2170: $allowed=1;
2171: $thisrole.='.'.$role_code;
1.217 raeburn 2172: }
1.329 raeburn 2173: }
1.406.2.6 raeburn 2174: if ($area=~m{^/($match_domain/$match_courseid/(\w+))}) {
2175: $csec = $2;
2176: $carea.='<br />'.&mt('Section: [_1]',$csec);
2177: $sortkey.="\0$csec";
1.329 raeburn 2178: if (!$allowed) {
1.406.2.6 raeburn 2179: if ($env{'request.course.sec'} eq $csec) {
2180: if (&Apache::lonnet::allowed('c'.$role_code,$1)) {
1.329 raeburn 2181: $allowed = 1;
1.217 raeburn 2182: }
2183: }
2184: }
1.329 raeburn 2185: }
2186: $area=$carea;
2187: } else {
2188: $sortkey.="\0".$area;
2189: # Determine if current user is able to revoke privileges
2190: if ($area=~m{^/($match_domain)/}) {
2191: if ((&Apache::lonnet::allowed('c'.$role_code,$1)) ||
2192: (&Apache::lonnet::allowed('c'.$role_code,$ccdomain))) {
2193: $allowed=1;
1.217 raeburn 2194: }
1.329 raeburn 2195: if (((&Apache::lonnet::allowed('dro',$1)) ||
2196: (&Apache::lonnet::allowed('dro',$ccdomain))) &&
2197: ($role_code ne 'dc')) {
2198: $delallowed=1;
1.217 raeburn 2199: }
1.329 raeburn 2200: } else {
2201: if (&Apache::lonnet::allowed('c'.$role_code,'/')) {
1.217 raeburn 2202: $allowed=1;
2203: }
2204: }
1.363 raeburn 2205: if ($role_code eq 'ca' || $role_code eq 'au' || $role_code eq 'aa') {
1.377 raeburn 2206: $class='Authoring Space';
1.329 raeburn 2207: } elsif ($role_code eq 'su') {
2208: $class='System';
1.217 raeburn 2209: } else {
1.329 raeburn 2210: $class='Domain';
1.217 raeburn 2211: }
1.329 raeburn 2212: }
2213: if (($role_code eq 'ca') || ($role_code eq 'aa')) {
2214: $area=~m{/($match_domain)/($match_username)};
2215: if (&Apache::lonuserutils::authorpriv($2,$1)) {
2216: $allowed=1;
1.406.2.20.2. (raeburn 2217:): } elsif (&Apache::lonuserutils::coauthorpriv($2,$1)) {
2218:): $allowed=1;
1.217 raeburn 2219: } else {
1.329 raeburn 2220: $allowed=0;
1.217 raeburn 2221: }
1.329 raeburn 2222: }
2223: my $row = '';
1.406.2.6 raeburn 2224: if ($showall) {
2225: $row.= '<td>';
2226: if (($active) && ($allowed)) {
2227: $row.= '<input type="checkbox" name="rev:'.$thisrole.'" />';
1.217 raeburn 2228: } else {
1.406.2.6 raeburn 2229: if ($active) {
2230: $row.=' ';
2231: } else {
2232: $row.=&mt('expired or revoked');
2233: }
1.217 raeburn 2234: }
1.406.2.6 raeburn 2235: $row.='</td><td>';
2236: if ($allowed && !$active) {
2237: $row.= '<input type="checkbox" name="ren:'.$thisrole.'" />';
2238: } else {
2239: $row.=' ';
2240: }
2241: $row.='</td><td>';
2242: if ($delallowed) {
2243: $row.= '<input type="checkbox" name="del:'.$thisrole.'" />';
2244: } else {
2245: $row.=' ';
2246: }
2247: $row.= '</td>';
1.329 raeburn 2248: }
2249: my $plaintext='';
2250: if (!$croletitle) {
1.375 raeburn 2251: $plaintext=&Apache::lonnet::plaintext($role_code,$class);
2252: if (($showcredits) && ($credits ne '')) {
2253: $plaintext .= '<br/ ><span class="LC_nobreak">'.
2254: '<span class="LC_fontsize_small">'.
2255: &mt('Credits: [_1]',$credits).
2256: '</span></span>';
2257: }
1.329 raeburn 2258: } else {
2259: $plaintext=
1.395 bisitz 2260: &mt('Custom role [_1][_2]defined by [_3]',
1.346 bisitz 2261: '"'.$croletitle.'"',
2262: '<br />',
2263: $croleuname.':'.$croleudom);
1.329 raeburn 2264: }
1.406.2.6 raeburn 2265: $row.= '<td>'.$plaintext.'</td>'.
2266: '<td>'.$area.'</td>'.
2267: '<td>'.($role_start_time?&Apache::lonlocal::locallocaltime($role_start_time)
2268: : ' ' ).'</td>'.
2269: '<td>'.($role_end_time ?&Apache::lonlocal::locallocaltime($role_end_time)
2270: : ' ' ).'</td>';
1.329 raeburn 2271: $sortrole{$sortkey}=$envkey;
2272: $roletext{$envkey}=$row;
2273: $roleclass{$envkey}=$class;
1.406.2.6 raeburn 2274: if ($allowed) {
2275: $rolepriv{$envkey}='edit';
2276: } else {
2277: if ($context eq 'domain') {
1.406.2.7 raeburn 2278: if ((&Apache::lonnet::allowed('vur',$ccdomain)) &&
2279: ($envkey=~m{^/$ccdomain/})) {
1.406.2.6 raeburn 2280: $rolepriv{$envkey}='view';
2281: }
2282: } elsif ($context eq 'course') {
2283: if ((&Apache::lonnet::allowed('vcl',$env{'request.course.id'})) ||
2284: ($env{'request.course.sec'} && ($env{'request.course.sec'} eq $csec) &&
2285: &Apache::lonnet::allowed('vcl',$env{'request.course.id'}.'/'.$env{'request.course.sec'}))) {
2286: $rolepriv{$envkey}='view';
2287: }
2288: }
2289: }
1.329 raeburn 2290: } # end of foreach (table building loop)
2291:
2292: my $rolesdisplay = 0;
2293: my %output = ();
1.377 raeburn 2294: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2295: $output{$type} = '';
2296: foreach my $which (sort {uc($a) cmp uc($b)} (keys(%sortrole))) {
2297: if ( ($roleclass{$sortrole{$which}} =~ /^\Q$type\E/ ) && ($rolepriv{$sortrole{$which}}) ) {
2298: $output{$type}.=
2299: &Apache::loncommon::start_data_table_row().
2300: $roletext{$sortrole{$which}}.
2301: &Apache::loncommon::end_data_table_row();
1.217 raeburn 2302: }
1.329 raeburn 2303: }
2304: unless($output{$type} eq '') {
2305: $output{$type} = '<tr class="LC_info_row">'.
2306: "<td align='center' colspan='7'>".&mt($type)."</td></tr>".
2307: $output{$type};
2308: $rolesdisplay = 1;
2309: }
2310: }
2311: if ($rolesdisplay == 1) {
2312: my $contextrole='';
2313: if ($env{'request.course.id'}) {
2314: if (&Apache::loncommon::course_type() eq 'Community') {
2315: $contextrole = &mt('Existing Roles in this Community');
1.290 bisitz 2316: } else {
1.329 raeburn 2317: $contextrole = &mt('Existing Roles in this Course');
1.290 bisitz 2318: }
1.329 raeburn 2319: } elsif ($env{'request.role'} =~ /^au\./) {
1.377 raeburn 2320: $contextrole = &mt('Existing Co-Author Roles in your Authoring Space');
1.406.2.20.2. (raeburn 2321:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)/$}) {
2322:): $contextrole = &mt('Existing Co-Author Roles in [_1] Authoring Space',
2323:): '<i>'.$1.'_'.$2.'</i>');
1.329 raeburn 2324: } else {
1.406.2.6 raeburn 2325: if ($showall) {
2326: $contextrole = &mt('Existing Roles in this Domain');
2327: } elsif ($showactive) {
2328: $contextrole = &mt('Unexpired Roles in this Domain');
2329: } elsif ($showexpired) {
2330: $contextrole = &mt('Expired or Revoked Roles in this Domain');
2331: }
1.329 raeburn 2332: }
1.393 raeburn 2333: $r->print('<div class="LC_left_float">'.
1.375 raeburn 2334: '<fieldset><legend>'.$contextrole.'</legend>'.
1.217 raeburn 2335: &Apache::loncommon::start_data_table("LC_createuser").
1.406.2.6 raeburn 2336: &Apache::loncommon::start_data_table_header_row());
2337: if ($showall) {
2338: $r->print(
2339: '<th>'.$lt{'rev'}.'</th><th>'.$lt{'ren'}.'</th><th>'.$lt{'del'}.'</th>'
2340: );
2341: } elsif ($showexpired) {
2342: $r->print('<th>'.$lt{'rev'}.'</th>');
2343: }
2344: $r->print(
2345: '<th>'.$lt{'rol'}.'</th><th>'.$lt{'ext'}.'</th>'.
2346: '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'.
1.217 raeburn 2347: &Apache::loncommon::end_data_table_header_row());
1.377 raeburn 2348: foreach my $type ('Authoring Space','Course','Community','Domain','System','Unknown') {
1.329 raeburn 2349: if ($output{$type}) {
2350: $r->print($output{$type}."\n");
1.217 raeburn 2351: }
2352: }
1.375 raeburn 2353: $r->print(&Apache::loncommon::end_data_table().
2354: '</fieldset></div>');
1.329 raeburn 2355: }
1.217 raeburn 2356: return;
2357: }
2358:
1.218 raeburn 2359: sub new_coauthor_roles {
2360: my ($r,$ccuname,$ccdomain) = @_;
2361: my $addrolesdisplay = 0;
2362: #
2363: # Co-Author
2364: #
1.406.2.20.2. (raeburn 2365:): my ($cuname,$cudom);
2366:): if (($env{'request.role'} eq "au./$env{'user.domain'}/") ||
2367:): ($env{'request.role'} eq "dc./$env{'user.domain'}/")) {
2368:): $cuname=$env{'user.name'};
2369:): $cudom=$env{'request.role.domain'};
1.218 raeburn 2370: # No sense in assigning co-author role to yourself
1.406.2.20.2. (raeburn 2371:): if ((&Apache::lonuserutils::authorpriv($cuname,$cudom)) &&
2372:): ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
2373:): $addrolesdisplay = 1;
2374:): }
2375:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2376:): ($cudom,$cuname) = ($1,$2);
2377:): if ((&Apache::lonuserutils::coauthorpriv($cuname,$cudom)) &&
2378:): ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain) &&
2379:): ($cudom ne $ccdomain || $cuname ne $ccuname)) {
2380:): $addrolesdisplay = 1;
2381:): }
2382:): }
2383:): if ($addrolesdisplay) {
1.218 raeburn 2384: my %lt=&Apache::lonlocal::texthash(
1.377 raeburn 2385: 'cs' => "Authoring Space",
1.218 raeburn 2386: 'act' => "Activate",
2387: 'rol' => "Role",
2388: 'ext' => "Extent",
2389: 'sta' => "Start",
2390: 'end' => "End",
2391: 'cau' => "Co-Author",
2392: 'caa' => "Assistant Co-Author",
2393: 'ssd' => "Set Start Date",
2394: 'sed' => "Set End Date"
2395: );
2396: $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
2397: &Apache::loncommon::start_data_table()."\n".
2398: &Apache::loncommon::start_data_table_header_row()."\n".
2399: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
2400: '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
2401: '<th>'.$lt{'end'}.'</th>'."\n".
2402: &Apache::loncommon::end_data_table_header_row()."\n".
2403: &Apache::loncommon::start_data_table_row().'
2404: <td>
1.291 bisitz 2405: <input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_ca" />
1.218 raeburn 2406: </td>
2407: <td>'.$lt{'cau'}.'</td>
2408: <td>'.$cudom.'_'.$cuname.'</td>
2409: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
2410: <a href=
2411: "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>
2412: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
2413: <a href=
2414: "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".
2415: &Apache::loncommon::end_data_table_row()."\n".
2416: &Apache::loncommon::start_data_table_row()."\n".
1.291 bisitz 2417: '<td><input type="checkbox" name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
1.218 raeburn 2418: <td>'.$lt{'caa'}.'</td>
2419: <td>'.$cudom.'_'.$cuname.'</td>
2420: <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
2421: <a href=
2422: "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>
2423: <td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
2424: <a href=
2425: "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".
2426: &Apache::loncommon::end_data_table_row()."\n".
2427: &Apache::loncommon::end_data_table());
2428: } elsif ($env{'request.role'} =~ /^au\./) {
2429: if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
2430: $env{'request.role.domain'}))) {
2431: $r->print('<span class="LC_error">'.
2432: &mt('You do not have privileges to assign co-author roles.').
2433: '</span>');
2434: } elsif (($env{'user.name'} eq $ccuname) &&
2435: ($env{'user.domain'} eq $ccdomain)) {
1.377 raeburn 2436: $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 2437: }
1.406.2.20.2. (raeburn 2438:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
2439:): if (!(&Apache::lonuserutils::coauthorpriv($2,$1))) {
2440:): $r->print('<span class="LC_error">'.
2441:): &mt('You do not have privileges to assign co-author roles.').
2442:): '</span>');
2443:): } elsif (($env{'user.name'} eq $ccuname) &&
2444:): ($env{'user.domain'} eq $ccdomain)) {
2445:): $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'));
2446:): } elsif (($cudom eq $ccdomain) && ($cuname eq $ccuname)) {
2447:): $r->print(&mt("Assigning a co-author or assistant co-author role to an Authoring Space's author is not permitted"));
2448:): }
1.218 raeburn 2449: }
2450: return $addrolesdisplay;;
2451: }
2452:
2453: sub new_domain_roles {
1.357 raeburn 2454: my ($r,$ccdomain) = @_;
1.218 raeburn 2455: my $addrolesdisplay = 0;
2456: #
2457: # Domain level
2458: #
2459: my $num_domain_level = 0;
2460: my $domaintext =
2461: '<h4>'.&mt('Domain Level').'</h4>'.
2462: &Apache::loncommon::start_data_table().
2463: &Apache::loncommon::start_data_table_header_row().
2464: '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
2465: &mt('Extent').'</th>'.
2466: '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
2467: &Apache::loncommon::end_data_table_header_row();
1.312 raeburn 2468: my @allroles = &Apache::lonuserutils::roles_by_context('domain');
1.218 raeburn 2469: foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
1.312 raeburn 2470: foreach my $role (@allroles) {
2471: next if ($role eq 'ad');
1.357 raeburn 2472: next if (($role eq 'au') && ($ccdomain ne $thisdomain));
1.218 raeburn 2473: if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
2474: my $plrole=&Apache::lonnet::plaintext($role);
2475: my %lt=&Apache::lonlocal::texthash(
2476: 'ssd' => "Set Start Date",
2477: 'sed' => "Set End Date"
2478: );
2479: $num_domain_level ++;
2480: $domaintext .=
2481: &Apache::loncommon::start_data_table_row().
1.291 bisitz 2482: '<td><input type="checkbox" name="act_'.$thisdomain.'_'.$role.'" /></td>
1.218 raeburn 2483: <td>'.$plrole.'</td>
2484: <td>'.$thisdomain.'</td>
2485: <td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
2486: <a href=
2487: "javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
2488: <td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
2489: <a href=
2490: "javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
2491: &Apache::loncommon::end_data_table_row();
2492: }
2493: }
2494: }
2495: $domaintext.= &Apache::loncommon::end_data_table();
2496: if ($num_domain_level > 0) {
2497: $r->print($domaintext);
2498: $addrolesdisplay = 1;
2499: }
2500: return $addrolesdisplay;
2501: }
2502:
1.188 raeburn 2503: sub user_authentication {
1.406.2.17 raeburn 2504: my ($ccuname,$ccdomain,$formname,$crstype,$permission) = @_;
1.188 raeburn 2505: my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);
1.227 raeburn 2506: my $outcome;
1.406.2.6 raeburn 2507: my %lt=&Apache::lonlocal::texthash(
2508: 'err' => "ERROR",
2509: 'uuas' => "This user has an unrecognized authentication scheme",
2510: 'adcs' => "Please alert a domain coordinator of this situation",
2511: 'sldb' => "Please specify login data below",
2512: 'ld' => "Login Data"
2513: );
1.188 raeburn 2514: # Check for a bad authentication type
2515: if ($currentauth !~ /^(krb4|krb5|unix|internal|localauth):/) {
2516: # bad authentication scheme
2517: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
1.227 raeburn 2518: &initialize_authen_forms($ccdomain,$formname);
2519:
1.190 raeburn 2520: my $choices = &Apache::lonuserutils::set_login($ccdomain,$authformkrb,$authformint,$authformloc);
1.188 raeburn 2521: $outcome = <<ENDBADAUTH;
2522: <script type="text/javascript" language="Javascript">
1.301 bisitz 2523: // <![CDATA[
1.188 raeburn 2524: $loginscript
1.301 bisitz 2525: // ]]>
1.188 raeburn 2526: </script>
2527: <span class="LC_error">$lt{'err'}:
2528: $lt{'uuas'} ($currentauth). $lt{'sldb'}.</span>
2529: <h3>$lt{'ld'}</h3>
2530: $choices
2531: ENDBADAUTH
2532: } else {
2533: # This user is not allowed to modify the user's
2534: # authentication scheme, so just notify them of the problem
2535: $outcome = <<ENDBADAUTH;
2536: <span class="LC_error"> $lt{'err'}:
2537: $lt{'uuas'} ($currentauth). $lt{'adcs'}.
2538: </span>
2539: ENDBADAUTH
2540: }
2541: } else { # Authentication type is valid
1.227 raeburn 2542: &initialize_authen_forms($ccdomain,$formname,$currentauth,'modifyuser');
1.205 raeburn 2543: my ($authformcurrent,$can_modify,@authform_others) =
1.188 raeburn 2544: &modify_login_block($ccdomain,$currentauth);
2545: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2546: # Current user has login modification privileges
2547: $outcome =
2548: '<script type="text/javascript" language="Javascript">'."\n".
1.301 bisitz 2549: '// <![CDATA['."\n".
1.188 raeburn 2550: $loginscript."\n".
1.301 bisitz 2551: '// ]]>'."\n".
1.188 raeburn 2552: '</script>'."\n".
2553: '<h3>'.$lt{'ld'}.'</h3>'.
2554: &Apache::loncommon::start_data_table().
1.205 raeburn 2555: &Apache::loncommon::start_data_table_row().
1.188 raeburn 2556: '<td>'.$authformnop;
1.406.2.6 raeburn 2557: if (($can_modify) && (&Apache::lonnet::allowed('mau',$ccdomain))) {
1.188 raeburn 2558: $outcome .= '</td>'."\n".
2559: &Apache::loncommon::end_data_table_row().
2560: &Apache::loncommon::start_data_table_row().
2561: '<td>'.$authformcurrent.'</td>'.
2562: &Apache::loncommon::end_data_table_row()."\n";
2563: } else {
1.200 raeburn 2564: $outcome .= ' ('.$authformcurrent.')</td>'.
2565: &Apache::loncommon::end_data_table_row()."\n";
1.188 raeburn 2566: }
1.406.2.6 raeburn 2567: if (&Apache::lonnet::allowed('mau',$ccdomain)) {
2568: foreach my $item (@authform_others) {
2569: $outcome .= &Apache::loncommon::start_data_table_row().
2570: '<td>'.$item.'</td>'.
2571: &Apache::loncommon::end_data_table_row()."\n";
2572: }
1.188 raeburn 2573: }
1.205 raeburn 2574: $outcome .= &Apache::loncommon::end_data_table();
1.188 raeburn 2575: } else {
1.406.2.17 raeburn 2576: if (($currentauth =~ /^internal:/) &&
2577: (&Apache::lonuserutils::can_change_internalpass($ccuname,$ccdomain,$crstype,$permission))) {
2578: $outcome = <<"ENDJS";
2579: <script type="text/javascript">
2580: // <![CDATA[
2581: function togglePwd(form) {
2582: if (form.newintpwd.length) {
2583: if (document.getElementById('LC_ownersetpwd')) {
2584: for (var i=0; i<form.newintpwd.length; i++) {
2585: if (form.newintpwd[i].checked) {
2586: if (form.newintpwd[i].value == 1) {
2587: document.getElementById('LC_ownersetpwd').style.display = 'inline-block';
2588: } else {
2589: document.getElementById('LC_ownersetpwd').style.display = 'none';
2590: }
2591: }
2592: }
2593: }
2594: }
2595: }
2596: // ]]>
2597: </script>
2598: ENDJS
2599:
2600: $outcome .= '<h3>'.$lt{'ld'}.'</h3>'.
2601: &Apache::loncommon::start_data_table().
2602: &Apache::loncommon::start_data_table_row().
2603: '<td>'.&mt('Internally authenticated').'<br />'.&mt("Change user's password?").
2604: '<label><input type="radio" name="newintpwd" value="0" checked="checked" onclick="togglePwd(this.form);" />'.
2605: &mt('No').'</label>'.(' 'x2).
2606: '<label><input type="radio" name="newintpwd" value="1" onclick="togglePwd(this.form);" />'.&mt('Yes').'</label>'.
2607: '<div id="LC_ownersetpwd" style="display:none">'.
2608: ' '.&mt('Password').' <input type="password" size="15" name="intarg" value="" />'.
2609: '<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>'.
2610: &Apache::loncommon::end_data_table_row().
2611: &Apache::loncommon::end_data_table();
2612: }
1.406.2.6 raeburn 2613: if (&Apache::lonnet::allowed('udp',$ccdomain)) {
2614: # Current user has rights to view domain preferences for user's domain
2615: my $result;
2616: if ($currentauth =~ /^krb(4|5):([^:]*)$/) {
2617: my ($krbver,$krbrealm) = ($1,$2);
2618: if ($krbrealm eq '') {
2619: $result = &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2620: } else {
2621: $result = &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
1.406.2.9 raeburn 2622: $krbrealm,$krbver);
1.406.2.6 raeburn 2623: }
2624: } elsif ($currentauth =~ /^internal:/) {
2625: $result = &mt('Currently internally authenticated.');
2626: } elsif ($currentauth =~ /^localauth:/) {
2627: $result = &mt('Currently using local (institutional) authentication.');
2628: } elsif ($currentauth =~ /^unix:/) {
2629: $result = &mt('Currently Filesystem Authenticated.');
2630: }
2631: $outcome = '<h3>'.$lt{'ld'}.'</h3>'.
2632: &Apache::loncommon::start_data_table().
2633: &Apache::loncommon::start_data_table_row().
2634: '<td>'.$result.'</td>'.
2635: &Apache::loncommon::end_data_table_row()."\n".
2636: &Apache::loncommon::end_data_table();
2637: } elsif (&Apache::lonnet::allowed('mau',$env{'request.role.domain'})) {
1.188 raeburn 2638: my %lt=&Apache::lonlocal::texthash(
2639: 'ccld' => "Change Current Login Data",
2640: 'yodo' => "You do not have privileges to modify the authentication configuration for this user.",
2641: 'ifch' => "If a change is required, contact a domain coordinator for the domain",
2642: );
2643: $outcome .= <<ENDNOPRIV;
2644: <h3>$lt{'ccld'}</h3>
2645: $lt{'yodo'} $lt{'ifch'}: $ccdomain
1.235 raeburn 2646: <input type="hidden" name="login" value="nochange" />
1.188 raeburn 2647: ENDNOPRIV
2648: }
2649: }
2650: } ## End of "check for bad authentication type" logic
2651: return $outcome;
2652: }
2653:
1.187 raeburn 2654: sub modify_login_block {
2655: my ($dom,$currentauth) = @_;
2656: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2657: my ($authnum,%can_assign) =
2658: &Apache::loncommon::get_assignable_auth($dom);
1.205 raeburn 2659: my ($authformcurrent,@authform_others,$show_override_msg);
1.187 raeburn 2660: if ($currentauth=~/^krb(4|5):/) {
2661: $authformcurrent=$authformkrb;
2662: if ($can_assign{'int'}) {
1.205 raeburn 2663: push(@authform_others,$authformint);
1.187 raeburn 2664: }
2665: if ($can_assign{'loc'}) {
1.205 raeburn 2666: push(@authform_others,$authformloc);
1.187 raeburn 2667: }
2668: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
2669: $show_override_msg = 1;
2670: }
2671: } elsif ($currentauth=~/^internal:/) {
2672: $authformcurrent=$authformint;
2673: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2674: push(@authform_others,$authformkrb);
1.187 raeburn 2675: }
2676: if ($can_assign{'loc'}) {
1.205 raeburn 2677: push(@authform_others,$authformloc);
1.187 raeburn 2678: }
2679: if ($can_assign{'int'}) {
2680: $show_override_msg = 1;
2681: }
2682: } elsif ($currentauth=~/^unix:/) {
2683: $authformcurrent=$authformfsys;
2684: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2685: push(@authform_others,$authformkrb);
1.187 raeburn 2686: }
2687: if ($can_assign{'int'}) {
1.205 raeburn 2688: push(@authform_others,$authformint);
1.187 raeburn 2689: }
2690: if ($can_assign{'loc'}) {
1.205 raeburn 2691: push(@authform_others,$authformloc);
1.187 raeburn 2692: }
2693: if ($can_assign{'fsys'}) {
2694: $show_override_msg = 1;
2695: }
2696: } elsif ($currentauth=~/^localauth:/) {
2697: $authformcurrent=$authformloc;
2698: if (($can_assign{'krb4'}) || ($can_assign{'krb5'})) {
1.205 raeburn 2699: push(@authform_others,$authformkrb);
1.187 raeburn 2700: }
2701: if ($can_assign{'int'}) {
1.205 raeburn 2702: push(@authform_others,$authformint);
1.187 raeburn 2703: }
2704: if ($can_assign{'loc'}) {
2705: $show_override_msg = 1;
2706: }
2707: }
2708: if ($show_override_msg) {
1.205 raeburn 2709: $authformcurrent = '<table><tr><td colspan="3">'.$authformcurrent.
2710: '</td></tr>'."\n".
2711: '<tr><td> </td>'.
2712: '<td><b>'.&mt('Currently in use').'</b></td>'.
2713: '<td align="right"><span class="LC_cusr_emph">'.
1.187 raeburn 2714: &mt('will override current values').
1.205 raeburn 2715: '</span></td></tr></table>';
1.187 raeburn 2716: }
1.205 raeburn 2717: return ($authformcurrent,$show_override_msg,@authform_others);
1.187 raeburn 2718: }
2719:
1.188 raeburn 2720: sub personal_data_display {
1.406.2.20.2. (raeburn 2721:): my ($ccuname,$ccdomain,$newuser,$context,$inst_results,$readonly,$rolesarray,$now,
1.406.2.20 raeburn 2722: $captchaform,$emailusername,$usertype,$usernameset,$condition,$excluded,$showsubmit) = @_;
1.406.2.20.2. (raeburn 2723:): my ($output,%userenv,%canmodify,%canmodify_status,$disabled);
1.219 raeburn 2724: my @userinfo = ('firstname','middlename','lastname','generation',
2725: 'permanentemail','id');
1.252 raeburn 2726: my $rowcount = 0;
2727: my $editable = 0;
1.391 raeburn 2728: my %textboxsize = (
2729: firstname => '15',
2730: middlename => '15',
2731: lastname => '15',
2732: generation => '5',
2733: permanentemail => '25',
2734: id => '15',
2735: );
2736:
2737: my %lt=&Apache::lonlocal::texthash(
2738: 'pd' => "Personal Data",
2739: 'firstname' => "First Name",
2740: 'middlename' => "Middle Name",
2741: 'lastname' => "Last Name",
2742: 'generation' => "Generation",
2743: 'permanentemail' => "Permanent e-mail address",
2744: 'id' => "Student/Employee ID",
2745: 'lg' => "Login Data",
2746: 'inststatus' => "Affiliation",
2747: 'email' => 'E-mail address',
2748: 'valid' => 'Validation',
1.406.2.16 raeburn 2749: 'username' => 'Username',
1.391 raeburn 2750: );
2751:
2752: %canmodify_status =
1.286 raeburn 2753: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
2754: ['inststatus'],$rolesarray);
1.253 raeburn 2755: if (!$newuser) {
1.188 raeburn 2756: # Get the users information
2757: %userenv = &Apache::lonnet::get('environment',
2758: ['firstname','middlename','lastname','generation',
1.286 raeburn 2759: 'permanentemail','id','inststatus'],$ccdomain,$ccuname);
1.219 raeburn 2760: %canmodify =
2761: &Apache::lonuserutils::can_modify_userinfo($context,$ccdomain,
1.252 raeburn 2762: \@userinfo,$rolesarray);
1.257 raeburn 2763: } elsif ($context eq 'selfcreate') {
1.391 raeburn 2764: if ($newuser eq 'email') {
1.396 raeburn 2765: if (ref($emailusername) eq 'HASH') {
2766: if (ref($emailusername->{$usertype}) eq 'HASH') {
2767: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.406.2.16 raeburn 2768: @userinfo = ();
1.396 raeburn 2769: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
2770: foreach my $field (@{$infofields}) {
2771: if ($emailusername->{$usertype}->{$field}) {
2772: push(@userinfo,$field);
2773: $canmodify{$field} = 1;
2774: unless ($textboxsize{$field}) {
2775: $textboxsize{$field} = 25;
2776: }
2777: unless ($lt{$field}) {
2778: $lt{$field} = $infotitles->{$field};
2779: }
2780: if ($emailusername->{$usertype}->{$field} eq 'required') {
2781: $lt{$field} .= '<b>*</b>';
2782: }
1.391 raeburn 2783: }
2784: }
2785: }
2786: }
2787: }
2788: } else {
2789: %canmodify = &selfcreate_canmodify($context,$ccdomain,\@userinfo,
2790: $inst_results,$rolesarray);
2791: }
1.406.2.20.2. (raeburn 2792:): } elsif ($readonly) {
2793:): $disabled = ' disabled="disabled"';
1.188 raeburn 2794: }
1.391 raeburn 2795:
1.188 raeburn 2796: my $genhelp=&Apache::loncommon::help_open_topic('Generation');
2797: $output = '<h3>'.$lt{'pd'}.'</h3>'.
2798: &Apache::lonhtmlcommon::start_pick_box();
1.391 raeburn 2799: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
1.406.2.16 raeburn 2800: my $size = 25;
2801: if ($condition) {
2802: if ($condition =~ /^\@[^\@]+$/) {
2803: $size = 10;
2804: } else {
2805: undef($condition);
2806: }
2807: }
2808: if ($excluded) {
2809: unless ($excluded =~ /^\@[^\@]+$/) {
2810: undef($condition);
2811: }
2812: }
1.396 raeburn 2813: $output .= &Apache::lonhtmlcommon::row_title($lt{'email'}.'<b>*</b>',undef,
1.391 raeburn 2814: 'LC_oddrow_value')."\n".
1.406.2.16 raeburn 2815: '<input type="text" name="uname" size="'.$size.'" value="" autocomplete="off" />';
2816: if ($condition) {
2817: $output .= $condition;
2818: } elsif ($excluded) {
2819: $output .= '<br /><span style="font-size: smaller">'.&mt('You must use an e-mail address that does not end with [_1]',
2820: $excluded).'</span>';
2821: }
2822: if ($usernameset eq 'first') {
2823: $output .= '<br /><span style="font-size: smaller">';
2824: if ($condition) {
2825: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before [_1]',
2826: $condition);
2827: } else {
2828: $output .= &mt('Your username in LON-CAPA will be the part of your e-mail address before the @');
2829: }
2830: $output .= '</span>';
2831: }
1.391 raeburn 2832: $rowcount ++;
2833: $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.20.2. (raeburn 2834:): my $upassone = '<input type="password" name="upass'.$now.'" size="20" autocomplete="new-password" />';
2835:): my $upasstwo = '<input type="password" name="upasscheck'.$now.'" size="20" autocomplete="new-password" />';
1.396 raeburn 2836: $output .= &Apache::lonhtmlcommon::row_title(&mt('Password').'<b>*</b>',
1.391 raeburn 2837: 'LC_pick_box_title',
2838: 'LC_oddrow_value')."\n".
2839: $upassone."\n".
2840: &Apache::lonhtmlcommon::row_closure(1)."\n".
1.396 raeburn 2841: &Apache::lonhtmlcommon::row_title(&mt('Confirm password').'<b>*</b>',
1.391 raeburn 2842: 'LC_pick_box_title',
2843: 'LC_oddrow_value')."\n".
2844: $upasstwo.
2845: &Apache::lonhtmlcommon::row_closure()."\n";
1.406.2.16 raeburn 2846: if ($usernameset eq 'free') {
2847: my $onclick = "toggleUsernameDisp(this,'selfcreateusername');";
2848: $output .= &Apache::lonhtmlcommon::row_title($lt{'username'},undef,'LC_oddrow_value')."\n".
1.406.2.20 raeburn 2849: '<span class="LC_nobreak">'.&mt('Use e-mail address: ').
2850: '<label><input type="radio" name="emailused" value="1" checked="checked" onclick="'.$onclick.'" />'.
2851: &mt('Yes').'</label>'.(' 'x2).
2852: '<label><input type="radio" name="emailused" value="0" onclick="'.$onclick.'" />'.
2853: &mt('No').'</label></span>'."\n".
1.406.2.16 raeburn 2854: '<div id="selfcreateusername" style="display: none; font-size: smaller">'.
2855: '<br /><span class="LC_nobreak">'.&mt('Preferred username').
2856: ' <input type="text" name="username" value="" size="20" autocomplete="off"/>'.
2857: '</span></div>'."\n".&Apache::lonhtmlcommon::row_closure(1);
2858: $rowcount ++;
2859: }
1.391 raeburn 2860: }
1.188 raeburn 2861: foreach my $item (@userinfo) {
2862: my $rowtitle = $lt{$item};
1.252 raeburn 2863: my $hiderow = 0;
1.188 raeburn 2864: if ($item eq 'generation') {
2865: $rowtitle = $genhelp.$rowtitle;
2866: }
1.252 raeburn 2867: my $row = &Apache::lonhtmlcommon::row_title($rowtitle,undef,'LC_oddrow_value')."\n";
1.188 raeburn 2868: if ($newuser) {
1.210 raeburn 2869: if (ref($inst_results) eq 'HASH') {
2870: if ($inst_results->{$item} ne '') {
1.252 raeburn 2871: $row .= '<input type="hidden" name="c'.$item.'" value="'.$inst_results->{$item}.'" />'.$inst_results->{$item};
1.210 raeburn 2872: } else {
1.252 raeburn 2873: if ($context eq 'selfcreate') {
1.391 raeburn 2874: if ($canmodify{$item}) {
1.394 raeburn 2875: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.252 raeburn 2876: $editable ++;
2877: } else {
2878: $hiderow = 1;
2879: }
1.253 raeburn 2880: } else {
1.406.2.20.2. (raeburn 2881:): $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2882: }
1.210 raeburn 2883: }
1.188 raeburn 2884: } else {
1.252 raeburn 2885: if ($context eq 'selfcreate') {
1.401 raeburn 2886: if ($canmodify{$item}) {
2887: if ($newuser eq 'email') {
2888: $row .= '<input type="text" name="'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2889: } else {
1.401 raeburn 2890: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="" autocomplete="off" />';
1.287 raeburn 2891: }
1.401 raeburn 2892: $editable ++;
2893: } else {
2894: $hiderow = 1;
1.252 raeburn 2895: }
1.253 raeburn 2896: } else {
1.406.2.20.2. (raeburn 2897:): $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value=""'.$disabled.' />';
1.252 raeburn 2898: }
1.188 raeburn 2899: }
2900: } else {
1.219 raeburn 2901: if ($canmodify{$item}) {
1.252 raeburn 2902: $row .= '<input type="text" name="c'.$item.'" size="'.$textboxsize{$item}.'" value="'.$userenv{$item}.'" />';
1.393 raeburn 2903: if (($item eq 'id') && (!$newuser)) {
2904: $row .= '<br />'.&Apache::lonuserutils::forceid_change($context);
2905: }
1.188 raeburn 2906: } else {
1.252 raeburn 2907: $row .= $userenv{$item};
1.188 raeburn 2908: }
2909: }
1.252 raeburn 2910: $row .= &Apache::lonhtmlcommon::row_closure(1);
2911: if (!$hiderow) {
2912: $output .= $row;
2913: $rowcount ++;
2914: }
1.188 raeburn 2915: }
1.286 raeburn 2916: if (($canmodify_status{'inststatus'}) || ($context ne 'selfcreate')) {
2917: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($ccdomain);
2918: if (ref($types) eq 'ARRAY') {
2919: if (@{$types} > 0) {
2920: my ($hiderow,$shown);
2921: if ($canmodify_status{'inststatus'}) {
2922: $shown = &pick_inst_statuses($userenv{'inststatus'},$usertypes,$types);
2923: } else {
2924: if ($userenv{'inststatus'} eq '') {
2925: $hiderow = 1;
1.334 raeburn 2926: } else {
2927: my @showitems;
2928: foreach my $item ( map { &unescape($_); } split(':',$userenv{'inststatus'})) {
2929: if (exists($usertypes->{$item})) {
2930: push(@showitems,$usertypes->{$item});
2931: } else {
2932: push(@showitems,$item);
2933: }
2934: }
2935: if (@showitems) {
2936: $shown = join(', ',@showitems);
2937: } else {
2938: $hiderow = 1;
2939: }
1.286 raeburn 2940: }
2941: }
2942: if (!$hiderow) {
1.389 bisitz 2943: my $row = &Apache::lonhtmlcommon::row_title(&mt('Affiliations'),undef,'LC_oddrow_value')."\n".
1.286 raeburn 2944: $shown.&Apache::lonhtmlcommon::row_closure(1);
2945: if ($context eq 'selfcreate') {
2946: $rowcount ++;
2947: }
2948: $output .= $row;
2949: }
2950: }
2951: }
2952: }
1.391 raeburn 2953: if (($context eq 'selfcreate') && ($newuser eq 'email')) {
2954: if ($captchaform) {
1.406.2.2 raeburn 2955: $output .= &Apache::lonhtmlcommon::row_title($lt{'valid'}.'*',
1.391 raeburn 2956: 'LC_pick_box_title')."\n".
2957: $captchaform."\n".'<br /><br />'.
2958: &Apache::lonhtmlcommon::row_closure(1);
2959: $rowcount ++;
2960: }
1.406.2.20 raeburn 2961: if ($showsubmit) {
2962: my $submit_text = &mt('Create account');
2963: $output .= &Apache::lonhtmlcommon::row_title()."\n".
2964: '<br /><input type="submit" name="createaccount" value="'.
2965: $submit_text.'" />';
2966: if ($usertype ne '') {
1.406.2.20.2. (raeburn 2967:): $output .= '<input type="hidden" name="type" value="'.
2968:): &HTML::Entities::encode($usertype,'\'<>"&').'" />';
1.406.2.20 raeburn 2969: }
1.406.2.20.2. (raeburn 2970:): $output .= &Apache::lonhtmlcommon::row_closure(1);
1.406.2.20 raeburn 2971: }
1.391 raeburn 2972: }
1.188 raeburn 2973: $output .= &Apache::lonhtmlcommon::end_pick_box();
1.206 raeburn 2974: if (wantarray) {
1.252 raeburn 2975: if ($context eq 'selfcreate') {
2976: return($output,$rowcount,$editable);
2977: } else {
1.388 bisitz 2978: return $output;
1.252 raeburn 2979: }
1.206 raeburn 2980: } else {
2981: return $output;
2982: }
1.188 raeburn 2983: }
2984:
1.286 raeburn 2985: sub pick_inst_statuses {
2986: my ($curr,$usertypes,$types) = @_;
2987: my ($output,$rem,@currtypes);
2988: if ($curr ne '') {
2989: @currtypes = map { &unescape($_); } split(/:/,$curr);
2990: }
2991: my $numinrow = 2;
2992: if (ref($types) eq 'ARRAY') {
2993: $output = '<table>';
2994: my $lastcolspan;
2995: for (my $i=0; $i<@{$types}; $i++) {
2996: if (defined($usertypes->{$types->[$i]})) {
2997: my $rem = $i%($numinrow);
2998: if ($rem == 0) {
2999: if ($i<@{$types}-1) {
3000: if ($i > 0) {
3001: $output .= '</tr>';
3002: }
3003: $output .= '<tr>';
3004: }
3005: } elsif ($i==@{$types}-1) {
3006: my $colsleft = $numinrow - $rem;
3007: if ($colsleft > 1) {
3008: $lastcolspan = ' colspan="'.$colsleft.'"';
3009: }
3010: }
3011: my $check = ' ';
3012: if (grep(/^\Q$types->[$i]\E$/,@currtypes)) {
3013: $check = ' checked="checked" ';
3014: }
3015: $output .= '<td class="LC_left_item"'.$lastcolspan.'>'.
3016: '<span class="LC_nobreak"><label>'.
3017: '<input type="checkbox" name="inststatus" '.
3018: 'value="'.$types->[$i].'"'.$check.'/>'.
3019: $usertypes->{$types->[$i]}.'</label></span></td>';
3020: }
3021: }
3022: $output .= '</tr></table>';
3023: }
3024: return $output;
3025: }
3026:
1.257 raeburn 3027: sub selfcreate_canmodify {
3028: my ($context,$dom,$userinfo,$inst_results,$rolesarray) = @_;
3029: if (ref($inst_results) eq 'HASH') {
3030: my @inststatuses = &get_inststatuses($inst_results);
3031: if (@inststatuses == 0) {
3032: @inststatuses = ('default');
3033: }
3034: $rolesarray = \@inststatuses;
3035: }
3036: my %canmodify =
3037: &Apache::lonuserutils::can_modify_userinfo($context,$dom,$userinfo,
3038: $rolesarray);
3039: return %canmodify;
3040: }
3041:
1.252 raeburn 3042: sub get_inststatuses {
3043: my ($insthashref) = @_;
3044: my @inststatuses = ();
3045: if (ref($insthashref) eq 'HASH') {
3046: if (ref($insthashref->{'inststatus'}) eq 'ARRAY') {
3047: @inststatuses = @{$insthashref->{'inststatus'}};
3048: }
3049: }
3050: return @inststatuses;
3051: }
3052:
1.4 www 3053: # ================================================================= Phase Three
1.42 matthew 3054: sub update_user_data {
1.406.2.17 raeburn 3055: my ($r,$context,$crstype,$brcrum,$showcredits,$permission) = @_;
1.101 albertel 3056: my $uhome=&Apache::lonnet::homeserver($env{'form.ccuname'},
3057: $env{'form.ccdomain'});
1.27 matthew 3058: # Error messages
1.188 raeburn 3059: my $error = '<span class="LC_error">'.&mt('Error').': ';
1.193 raeburn 3060: my $end = '</span><br /><br />';
3061: my $rtnlink = '<a href="javascript:backPage(document.userupdate,'.
1.188 raeburn 3062: "'$env{'form.prevphase'}','modify')".'" />'.
1.219 raeburn 3063: &mt('Return to previous page').'</a>'.
3064: &Apache::loncommon::end_page();
3065: my $now = time;
1.40 www 3066: my $title;
1.101 albertel 3067: if (exists($env{'form.makeuser'})) {
1.40 www 3068: $title='Set Privileges for New User';
3069: } else {
3070: $title='Modify User Privileges';
3071: }
1.213 raeburn 3072: my $newuser = 0;
1.160 raeburn 3073: my ($jsback,$elements) = &crumb_utilities();
3074: my $jscript = '<script type="text/javascript">'."\n".
1.301 bisitz 3075: '// <![CDATA['."\n".
3076: $jsback."\n".
3077: '// ]]>'."\n".
3078: '</script>'."\n";
1.406.2.7 raeburn 3079: my %breadcrumb_text = &singleuser_breadcrumb($crstype,$context,$env{'form.ccdomain'});
1.351 raeburn 3080: push (@{$brcrum},
3081: {href => "javascript:backPage(document.userupdate)",
3082: text => $breadcrumb_text{'search'},
3083: faq => 282,
3084: bug => 'Instructor Interface',}
3085: );
3086: if ($env{'form.prevphase'} eq 'userpicked') {
3087: push(@{$brcrum},
3088: {href => "javascript:backPage(document.userupdate,'get_user_info','select')",
3089: text => $breadcrumb_text{'userpicked'},
3090: faq => 282,
3091: bug => 'Instructor Interface',});
1.233 raeburn 3092: }
1.224 raeburn 3093: my $helpitem = 'Course_Change_Privileges';
3094: if ($env{'form.action'} eq 'singlestudent') {
3095: $helpitem = 'Course_Add_Student';
1.406.2.14 raeburn 3096: } elsif ($context eq 'author') {
3097: $helpitem = 'Author_Change_Privileges';
3098: } elsif ($context eq 'domain') {
3099: $helpitem = 'Domain_Change_Privileges';
1.224 raeburn 3100: }
1.351 raeburn 3101: push(@{$brcrum},
3102: {href => "javascript:backPage(document.userupdate,'$env{'form.prevphase'}','modify')",
3103: text => $breadcrumb_text{'modify'},
3104: faq => 282,
3105: bug => 'Instructor Interface',},
3106: {href => "/adm/createuser",
3107: text => "Result",
3108: faq => 282,
3109: bug => 'Instructor Interface',
3110: help => $helpitem});
3111: my $args = {bread_crumbs => $brcrum,
3112: bread_crumbs_component => 'User Management'};
3113: if ($env{'form.popup'}) {
3114: $args->{'no_nav_bar'} = 1;
3115: }
3116: $r->print(&Apache::loncommon::start_page($title,$jscript,$args));
1.188 raeburn 3117: $r->print(&update_result_form($uhome));
1.27 matthew 3118: # Check Inputs
1.101 albertel 3119: if (! $env{'form.ccuname'} ) {
1.193 raeburn 3120: $r->print($error.&mt('No login name specified').'.'.$end.$rtnlink);
1.27 matthew 3121: return;
3122: }
1.138 albertel 3123: if ( $env{'form.ccuname'} ne
3124: &LONCAPA::clean_username($env{'form.ccuname'}) ) {
1.281 bisitz 3125: $r->print($error.&mt('Invalid login name.').' '.
3126: &mt('Only letters, numbers, periods, dashes, @, and underscores are valid.').
1.193 raeburn 3127: $end.$rtnlink);
1.27 matthew 3128: return;
3129: }
1.101 albertel 3130: if (! $env{'form.ccdomain'} ) {
1.193 raeburn 3131: $r->print($error.&mt('No domain specified').'.'.$end.$rtnlink);
1.27 matthew 3132: return;
3133: }
1.138 albertel 3134: if ( $env{'form.ccdomain'} ne
3135: &LONCAPA::clean_domain($env{'form.ccdomain'}) ) {
1.281 bisitz 3136: $r->print($error.&mt('Invalid domain name.').' '.
3137: &mt('Only letters, numbers, periods, dashes, and underscores are valid.').
1.193 raeburn 3138: $end.$rtnlink);
1.27 matthew 3139: return;
3140: }
1.219 raeburn 3141: if ($uhome eq 'no_host') {
3142: $newuser = 1;
3143: }
1.101 albertel 3144: if (! exists($env{'form.makeuser'})) {
1.29 matthew 3145: # Modifying an existing user, so check the validity of the name
3146: if ($uhome eq 'no_host') {
1.389 bisitz 3147: $r->print(
3148: $error
3149: .'<p class="LC_error">'
3150: .&mt('Unable to determine home server for [_1] in domain [_2].',
3151: '"'.$env{'form.ccuname'}.'"','"'.$env{'form.ccdomain'}.'"')
3152: .'</p>');
1.29 matthew 3153: return;
3154: }
3155: }
1.27 matthew 3156: # Determine authentication method and password for the user being modified
3157: my $amode='';
3158: my $genpwd='';
1.101 albertel 3159: if ($env{'form.login'} eq 'krb') {
1.41 albertel 3160: $amode='krb';
1.101 albertel 3161: $amode.=$env{'form.krbver'};
3162: $genpwd=$env{'form.krbarg'};
3163: } elsif ($env{'form.login'} eq 'int') {
1.27 matthew 3164: $amode='internal';
1.101 albertel 3165: $genpwd=$env{'form.intarg'};
3166: } elsif ($env{'form.login'} eq 'fsys') {
1.27 matthew 3167: $amode='unix';
1.101 albertel 3168: $genpwd=$env{'form.fsysarg'};
3169: } elsif ($env{'form.login'} eq 'loc') {
1.27 matthew 3170: $amode='localauth';
1.101 albertel 3171: $genpwd=$env{'form.locarg'};
1.27 matthew 3172: $genpwd=" " if (!$genpwd);
1.101 albertel 3173: } elsif (($env{'form.login'} eq 'nochange') ||
3174: ($env{'form.login'} eq '' )) {
1.34 matthew 3175: # There is no need to tell the user we did not change what they
3176: # did not ask us to change.
1.35 matthew 3177: # If they are creating a new user but have not specified login
3178: # information this will be caught below.
1.30 matthew 3179: } else {
1.367 golterma 3180: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
3181: return;
1.27 matthew 3182: }
1.164 albertel 3183:
1.188 raeburn 3184: $r->print('<h3>'.&mt('User [_1] in domain [_2]',
1.367 golterma 3185: $env{'form.ccuname'}.' ('.&Apache::loncommon::plainname($env{'form.ccuname'},
3186: $env{'form.ccdomain'}).')', $env{'form.ccdomain'}).'</h3>');
3187: my %prog_state = &Apache::lonhtmlcommon::Create_PrgWin($r,2);
1.344 bisitz 3188:
1.193 raeburn 3189: my (%alerts,%rulematch,%inst_results,%curr_rules);
1.334 raeburn 3190: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
1.406.2.20.2. (raeburn 3191:): my @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.384 raeburn 3192: my @requestcourses = ('official','unofficial','community','textbook');
1.362 raeburn 3193: my @requestauthor = ('requestauthor');
1.406.2.20.2. (raeburn 3194:): my @authordefaults = ('webdav','editors','archive');
1.286 raeburn 3195: my ($othertitle,$usertypes,$types) =
3196: &Apache::loncommon::sorted_inst_types($env{'form.ccdomain'});
1.334 raeburn 3197: my %canmodify_status =
3198: &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},
3199: ['inststatus']);
1.101 albertel 3200: if ($env{'form.makeuser'}) {
1.164 albertel 3201: $r->print('<h3>'.&mt('Creating new account.').'</h3>');
1.27 matthew 3202: # Check for the authentication mode and password
3203: if (! $amode || ! $genpwd) {
1.193 raeburn 3204: $r->print($error.&mt('Invalid login mode or password').$end.$rtnlink);
1.27 matthew 3205: return;
1.18 albertel 3206: }
1.29 matthew 3207: # Determine desired host
1.101 albertel 3208: my $desiredhost = $env{'form.hserver'};
1.29 matthew 3209: if (lc($desiredhost) eq 'default') {
3210: $desiredhost = undef;
3211: } else {
1.147 albertel 3212: my %home_servers =
3213: &Apache::lonnet::get_servers($env{'form.ccdomain'},'library');
1.29 matthew 3214: if (! exists($home_servers{$desiredhost})) {
1.193 raeburn 3215: $r->print($error.&mt('Invalid home server specified').$end.$rtnlink);
3216: return;
3217: }
3218: }
3219: # Check ID format
3220: my %checkhash;
3221: my %checks = ('id' => 1);
3222: %{$checkhash{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}}} = (
1.219 raeburn 3223: 'newuser' => $newuser,
1.196 raeburn 3224: 'id' => $env{'form.cid'},
1.193 raeburn 3225: );
1.196 raeburn 3226: if ($env{'form.cid'} ne '') {
3227: &Apache::loncommon::user_rule_check(\%checkhash,\%checks,\%alerts,
3228: \%rulematch,\%inst_results,\%curr_rules);
3229: if (ref($alerts{'id'}) eq 'HASH') {
3230: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
3231: my $domdesc =
3232: &Apache::lonnet::domain($env{'form.ccdomain'},'description');
3233: if ($alerts{'id'}{$env{'form.ccdomain'}}{$env{'form.cid'}}) {
3234: my $userchkmsg;
3235: if (ref($curr_rules{$env{'form.ccdomain'}}) eq 'HASH') {
3236: $userchkmsg =
3237: &Apache::loncommon::instrule_disallow_msg('id',
3238: $domdesc,1).
3239: &Apache::loncommon::user_rule_formats($env{'form.ccdomain'},
3240: $domdesc,$curr_rules{$env{'form.ccdomain'}}{'id'},'id');
3241: }
3242: $r->print($error.&mt('Invalid ID format').$end.
3243: $userchkmsg.$rtnlink);
3244: return;
3245: }
3246: }
1.29 matthew 3247: }
3248: }
1.367 golterma 3249: &Apache::lonhtmlcommon::Increment_PrgWin($r, \%prog_state);
1.27 matthew 3250: # Call modifyuser
3251: my $result = &Apache::lonnet::modifyuser
1.193 raeburn 3252: ($env{'form.ccdomain'},$env{'form.ccuname'},$env{'form.cid'},
1.188 raeburn 3253: $amode,$genpwd,$env{'form.cfirstname'},
3254: $env{'form.cmiddlename'},$env{'form.clastname'},
3255: $env{'form.cgeneration'},undef,$desiredhost,
3256: $env{'form.cpermanentemail'});
1.77 www 3257: $r->print(&mt('Generating user').': '.$result);
1.219 raeburn 3258: $uhome = &Apache::lonnet::homeserver($env{'form.ccuname'},
1.101 albertel 3259: $env{'form.ccdomain'});
1.334 raeburn 3260: my (%changeHash,%newcustom,%changed,%changedinfo);
1.267 raeburn 3261: if ($uhome ne 'no_host') {
1.334 raeburn 3262: if ($context eq 'domain') {
1.378 raeburn 3263: foreach my $name ('portfolio','author') {
3264: if ($env{'form.custom_'.$name.'quota'} == 1) {
3265: if ($env{'form.'.$name.'quota'} eq '') {
3266: $newcustom{$name.'quota'} = 0;
3267: } else {
3268: $newcustom{$name.'quota'} = $env{'form.'.$name.'quota'};
3269: $newcustom{$name.'quota'} =~ s/[^\d\.]//g;
3270: }
3271: if ("a_admin($newcustom{$name.'quota'},\%changeHash,$name)) {
3272: $changed{$name.'quota'} = 1;
3273: }
1.334 raeburn 3274: }
3275: }
3276: foreach my $item (@usertools) {
3277: if ($env{'form.custom'.$item} == 1) {
3278: $newcustom{$item} = $env{'form.tools_'.$item};
3279: $changed{$item} = &tool_admin($item,$newcustom{$item},
3280: \%changeHash,'tools');
3281: }
1.267 raeburn 3282: }
1.334 raeburn 3283: foreach my $item (@requestcourses) {
1.341 raeburn 3284: if ($env{'form.custom'.$item} == 1) {
3285: $newcustom{$item} = $env{'form.crsreq_'.$item};
3286: if ($env{'form.crsreq_'.$item} eq 'autolimit') {
3287: $newcustom{$item} .= '=';
1.383 raeburn 3288: $env{'form.crsreq_'.$item.'_limit'} =~ s/\D+//g;
3289: if ($env{'form.crsreq_'.$item.'_limit'}) {
1.341 raeburn 3290: $newcustom{$item} .= $env{'form.crsreq_'.$item.'_limit'};
3291: }
1.334 raeburn 3292: }
1.341 raeburn 3293: $changed{$item} = &tool_admin($item,$newcustom{$item},
3294: \%changeHash,'requestcourses');
1.334 raeburn 3295: }
1.275 raeburn 3296: }
1.362 raeburn 3297: if ($env{'form.customrequestauthor'} == 1) {
3298: $newcustom{'requestauthor'} = $env{'form.requestauthor'};
3299: $changed{'requestauthor'} = &tool_admin('requestauthor',
3300: $newcustom{'requestauthor'},
3301: \%changeHash,'requestauthor');
3302: }
1.406.2.20.2. (raeburn 3303:): if ($env{'form.customeditors'} == 1) {
3304:): my @editors;
3305:): my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
3306:): if (@posseditors) {
3307:): foreach my $editor (@posseditors) {
3308:): if (grep(/^\Q$editor\E$/,@posseditors)) {
3309:): unless (grep(/^\Q$editor\E$/,@editors)) {
3310:): push(@editors,$editor);
3311:): }
3312:): }
3313:): }
3314:): }
3315:): if (@editors) {
3316:): @editors = sort(@editors);
3317:): $changed{'editors'} = &tool_admin('editors',join(',',@editors),
3318:): \%changeHash,'authordefaults');
3319:): }
3320:): }
3321:): if ($env{'form.customwebdav'} == 1) {
3322:): $newcustom{'webdav'} = $env{'form.authordefaults_webdav'};
3323:): $changed{'webdav'} = &tool_admin('webdav',$newcustom{'webdav'},
3324:): \%changeHash,'authordefaults');
3325:): }
3326:): if ($env{'form.customarchive'} == 1) {
3327:): $newcustom{'archive'} = $env{'form.authordefaults_archive'};
3328:): $changed{'archive'} = &tool_admin('archive',$newcustom{'archive'},
3329:): \%changeHash,'authordefaults');
3330:):
3331:): }
1.275 raeburn 3332: }
1.334 raeburn 3333: if ($canmodify_status{'inststatus'}) {
3334: if (exists($env{'form.inststatus'})) {
3335: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3336: if (@inststatuses > 0) {
3337: $changeHash{'inststatus'} = join(',',@inststatuses);
3338: $changed{'inststatus'} = $changeHash{'inststatus'};
1.306 raeburn 3339: }
3340: }
1.232 raeburn 3341: }
1.334 raeburn 3342: if (keys(%changed)) {
3343: foreach my $item (@userinfo) {
3344: $changeHash{$item} = $env{'form.c'.$item};
1.286 raeburn 3345: }
1.267 raeburn 3346: my $chgresult =
3347: &Apache::lonnet::put('environment',\%changeHash,
3348: $env{'form.ccdomain'},$env{'form.ccuname'});
3349: }
1.232 raeburn 3350: }
1.406.2.19 raeburn 3351: $r->print('<br />'.&mt('Home Server').': '.$uhome.' '.
1.219 raeburn 3352: &Apache::lonnet::hostname($uhome));
1.101 albertel 3353: } elsif (($env{'form.login'} ne 'nochange') &&
3354: ($env{'form.login'} ne '' )) {
1.27 matthew 3355: # Modify user privileges
3356: if (! $amode || ! $genpwd) {
1.193 raeburn 3357: $r->print($error.'Invalid login mode or password'.$end.$rtnlink);
1.27 matthew 3358: return;
1.20 harris41 3359: }
1.395 bisitz 3360: # Only allow authentication modification if the person has authority
1.101 albertel 3361: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.20 harris41 3362: $r->print('Modifying authentication: '.
1.31 matthew 3363: &Apache::lonnet::modifyuserauth(
1.101 albertel 3364: $env{'form.ccdomain'},$env{'form.ccuname'},
1.21 harris41 3365: $amode,$genpwd));
1.406.2.19 raeburn 3366: $r->print('<br />'.&mt('Home Server').': '.&Apache::lonnet::homeserver
1.101 albertel 3367: ($env{'form.ccuname'},$env{'form.ccdomain'}));
1.4 www 3368: } else {
1.27 matthew 3369: # Okay, this is a non-fatal error.
1.406.2.17 raeburn 3370: $r->print($error.&mt('You do not have privileges to modify the authentication configuration for this user.').$end);
1.27 matthew 3371: }
1.406.2.17 raeburn 3372: } elsif (($env{'form.intarg'} ne '') &&
3373: (&Apache::lonnet::queryauthenticate($env{'form.ccuname'},$env{'form.ccdomain'}) =~ /^internal:/) &&
3374: (&Apache::lonuserutils::can_change_internalpass($env{'form.ccuname'},$env{'form.ccdomain'},$crstype,$permission))) {
3375: $r->print('Modifying authentication: '.
3376: &Apache::lonnet::modifyuserauth(
3377: $env{'form.ccdomain'},$env{'form.ccuname'},
3378: 'internal',$env{'form.intarg'}));
1.28 matthew 3379: }
1.344 bisitz 3380: $r->rflush(); # Finish display of header before time consuming actions start
1.367 golterma 3381: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state);
1.28 matthew 3382: ##
1.375 raeburn 3383: my (@userroles,%userupdate,$cnum,$cdom,$defaultcredits,%namechanged);
1.213 raeburn 3384: if ($context eq 'course') {
1.375 raeburn 3385: ($cnum,$cdom) =
3386: &Apache::lonuserutils::get_course_identity();
1.318 raeburn 3387: $crstype = &Apache::loncommon::course_type($cdom.'_'.$cnum);
1.375 raeburn 3388: if ($showcredits) {
3389: $defaultcredits = &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
3390: }
1.213 raeburn 3391: }
1.101 albertel 3392: if (! $env{'form.makeuser'} ) {
1.28 matthew 3393: # Check for need to change
3394: my %userenv = &Apache::lonnet::get
1.134 raeburn 3395: ('environment',['firstname','middlename','lastname','generation',
1.378 raeburn 3396: 'id','permanentemail','portfolioquota','authorquota','inststatus',
1.406.2.20.2. (raeburn 3397:): 'tools.aboutme','tools.blog','tools.webdav',
3398:): 'tools.portfolio','tools.timezone','tools.portaccess',
3399:): 'authormanagers','authoreditors','authorarchive','requestauthor',
1.361 raeburn 3400: 'requestcourses.official','requestcourses.unofficial',
1.384 raeburn 3401: 'requestcourses.community','requestcourses.textbook',
3402: 'reqcrsotherdom.official','reqcrsotherdom.unofficial',
1.406.2.20.2. (raeburn 3403:): 'reqcrsotherdom.community','reqcrsotherdom.textbook',
3404:): 'domcoord.author'],
1.160 raeburn 3405: $env{'form.ccdomain'},$env{'form.ccuname'});
1.28 matthew 3406: my ($tmp) = keys(%userenv);
3407: if ($tmp =~ /^(con_lost|error)/i) {
3408: %userenv = ();
3409: }
1.406.2.20.2. (raeburn 3410:): unless (($userenv{'domcoord.author'} eq 'blocked') &&
3411:): (($env{'user.name'} ne $env{'form.ccuname'}) ||
3412:): ($env{'user.domain'} ne $env{'form.ccdomain'}))) {
3413:): push(@authordefaults,'managers');
3414:): }
1.206 raeburn 3415: my $no_forceid_alert;
3416: # Check to see if user information can be changed
3417: my %domconfig =
3418: &Apache::lonnet::get_dom('configuration',['usermodification'],
3419: $env{'form.ccdomain'});
1.213 raeburn 3420: my @statuses = ('active','future');
3421: my %roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},'userroles',\@statuses,undef,$env{'request.role.domain'});
3422: my ($auname,$audom);
1.220 raeburn 3423: if ($context eq 'author') {
1.206 raeburn 3424: $auname = $env{'user.name'};
3425: $audom = $env{'user.domain'};
3426: }
3427: foreach my $item (keys(%roles)) {
1.220 raeburn 3428: my ($rolenum,$roledom,$role) = split(/:/,$item,-1);
1.206 raeburn 3429: if ($context eq 'course') {
3430: if ($cnum ne '' && $cdom ne '') {
3431: if ($rolenum eq $cnum && $roledom eq $cdom) {
3432: if (!grep(/^\Q$role\E$/,@userroles)) {
3433: push(@userroles,$role);
3434: }
3435: }
3436: }
3437: } elsif ($context eq 'author') {
3438: if ($rolenum eq $auname && $roledom eq $audom) {
3439: if (!grep(/^\Q$role\E$/,@userroles)) {
3440: push(@userroles,$role);
3441: }
3442: }
3443: }
3444: }
1.220 raeburn 3445: if ($env{'form.action'} eq 'singlestudent') {
3446: if (!grep(/^st$/,@userroles)) {
3447: push(@userroles,'st');
3448: }
3449: } else {
3450: # Check for course or co-author roles being activated or re-enabled
3451: if ($context eq 'author' || $context eq 'course') {
3452: foreach my $key (keys(%env)) {
3453: if ($context eq 'author') {
3454: if ($key=~/^form\.act_\Q$audom\E_\Q$auname\E_([^_]+)/) {
3455: if (!grep(/^\Q$1\E$/,@userroles)) {
3456: push(@userroles,$1);
3457: }
3458: } elsif ($key =~/^form\.ren\:\Q$audom\E\/\Q$auname\E_([^_]+)/) {
3459: if (!grep(/^\Q$1\E$/,@userroles)) {
3460: push(@userroles,$1);
3461: }
1.206 raeburn 3462: }
1.220 raeburn 3463: } elsif ($context eq 'course') {
3464: if ($key=~/^form\.act_\Q$cdom\E_\Q$cnum\E_([^_]+)/) {
3465: if (!grep(/^\Q$1\E$/,@userroles)) {
3466: push(@userroles,$1);
3467: }
3468: } elsif ($key =~/^form\.ren\:\Q$cdom\E\/\Q$cnum\E(\/?\w*)_([^_]+)/) {
3469: if (!grep(/^\Q$1\E$/,@userroles)) {
3470: push(@userroles,$1);
3471: }
1.206 raeburn 3472: }
3473: }
3474: }
3475: }
3476: }
3477: #Check to see if we can change personal data for the user
3478: my (@mod_disallowed,@longroles);
3479: foreach my $role (@userroles) {
3480: if ($role eq 'cr') {
3481: push(@longroles,'Custom');
3482: } else {
1.318 raeburn 3483: push(@longroles,&Apache::lonnet::plaintext($role,$crstype));
1.206 raeburn 3484: }
3485: }
1.219 raeburn 3486: my %canmodify = &Apache::lonuserutils::can_modify_userinfo($context,$env{'form.ccdomain'},\@userinfo,\@userroles);
3487: foreach my $item (@userinfo) {
1.28 matthew 3488: # Strip leading and trailing whitespace
1.203 raeburn 3489: $env{'form.c'.$item} =~ s/(\s+$|^\s+)//g;
1.219 raeburn 3490: if (!$canmodify{$item}) {
1.207 raeburn 3491: if (defined($env{'form.c'.$item})) {
3492: if ($env{'form.c'.$item} ne $userenv{$item}) {
3493: push(@mod_disallowed,$item);
3494: }
1.206 raeburn 3495: }
3496: $env{'form.c'.$item} = $userenv{$item};
3497: }
1.28 matthew 3498: }
1.259 bisitz 3499: # Check to see if we can change the Student/Employee ID
1.196 raeburn 3500: my $forceid = $env{'form.forceid'};
3501: my $recurseid = $env{'form.recurseid'};
3502: my (%alerts,%rulematch,%idinst_results,%curr_rules,%got_rules);
1.203 raeburn 3503: my %uidhash = &Apache::lonnet::idrget($env{'form.ccdomain'},
3504: $env{'form.ccuname'});
3505: if (($uidhash{$env{'form.ccuname'}}) &&
3506: ($uidhash{$env{'form.ccuname'}}!~/error\:/) &&
3507: (!$forceid)) {
3508: if ($env{'form.cid'} ne $uidhash{$env{'form.ccuname'}}) {
3509: $env{'form.cid'} = $userenv{'id'};
1.293 bisitz 3510: $no_forceid_alert = &mt('New student/employee ID does not match existing ID for this user.')
1.259 bisitz 3511: .'<br />'
3512: .&mt("Change is not permitted without checking the 'Force ID change' checkbox on the previous page.")
3513: .'<br />'."\n";
1.203 raeburn 3514: }
3515: }
3516: if ($env{'form.cid'} ne $userenv{'id'}) {
1.196 raeburn 3517: my $checkhash;
3518: my $checks = { 'id' => 1 };
3519: $checkhash->{$env{'form.ccuname'}.':'.$env{'form.ccdomain'}} =
3520: { 'newuser' => $newuser,
3521: 'id' => $env{'form.cid'},
3522: };
3523: &Apache::loncommon::user_rule_check($checkhash,$checks,
3524: \%alerts,\%rulematch,\%idinst_results,\%curr_rules,\%got_rules);
3525: if (ref($alerts{'id'}) eq 'HASH') {
3526: if (ref($alerts{'id'}{$env{'form.ccdomain'}}) eq 'HASH') {
1.203 raeburn 3527: $env{'form.cid'} = $userenv{'id'};
1.196 raeburn 3528: }
3529: }
3530: }
1.378 raeburn 3531: my (%quotachanged,%oldquota,%newquota,%olddefquota,%newdefquota,
3532: $oldinststatus,$newinststatus,%oldisdefault,%newisdefault,%oldsettings,
1.339 raeburn 3533: %oldsettingstext,%newsettings,%newsettingstext,@disporder,
1.378 raeburn 3534: %oldsettingstatus,%newsettingstatus);
1.334 raeburn 3535: @disporder = ('inststatus');
3536: if ($env{'request.role.domain'} eq $env{'form.ccdomain'}) {
1.406.2.20.2. (raeburn 3537:): push(@disporder,('requestcourses','requestauthor','authordefaults'));
1.334 raeburn 3538: } else {
3539: push(@disporder,'reqcrsotherdom');
3540: }
3541: push(@disporder,('quota','tools'));
1.338 raeburn 3542: $oldinststatus = $userenv{'inststatus'};
1.378 raeburn 3543: foreach my $name ('portfolio','author') {
3544: ($olddefquota{$name},$oldsettingstatus{$name}) =
3545: &Apache::loncommon::default_quota($env{'form.ccdomain'},$oldinststatus,$name);
3546: ($newdefquota{$name},$newsettingstatus{$name}) = ($olddefquota{$name},$oldsettingstatus{$name});
3547: }
1.334 raeburn 3548: my %canshow;
1.220 raeburn 3549: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
1.334 raeburn 3550: $canshow{'quota'} = 1;
1.220 raeburn 3551: }
1.267 raeburn 3552: if (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
1.334 raeburn 3553: $canshow{'tools'} = 1;
1.267 raeburn 3554: }
1.275 raeburn 3555: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
1.334 raeburn 3556: $canshow{'requestcourses'} = 1;
1.300 raeburn 3557: } elsif (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
1.334 raeburn 3558: $canshow{'reqcrsotherdom'} = 1;
1.275 raeburn 3559: }
1.286 raeburn 3560: if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'})) {
1.334 raeburn 3561: $canshow{'inststatus'} = 1;
1.286 raeburn 3562: }
1.362 raeburn 3563: if (&Apache::lonnet::allowed('cau',$env{'form.ccdomain'})) {
3564: $canshow{'requestauthor'} = 1;
1.406.2.20.2. (raeburn 3565:): $canshow{'authordefaults'} = 1;
1.362 raeburn 3566: }
1.267 raeburn 3567: my (%changeHash,%changed);
1.286 raeburn 3568: if ($oldinststatus eq '') {
1.334 raeburn 3569: $oldsettings{'inststatus'} = $othertitle;
1.286 raeburn 3570: } else {
3571: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3572: $oldsettings{'inststatus'} = join(', ',map{ $usertypes->{ &unescape($_) }; } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3573: } else {
1.334 raeburn 3574: $oldsettings{'inststatus'} = join(', ',map{ &unescape($_); } (split(/:/,$userenv{'inststatus'})));
1.286 raeburn 3575: }
3576: }
3577: $changeHash{'inststatus'} = $userenv{'inststatus'};
1.334 raeburn 3578: if ($canmodify_status{'inststatus'}) {
3579: $canshow{'inststatus'} = 1;
1.286 raeburn 3580: if (exists($env{'form.inststatus'})) {
3581: my @inststatuses = &Apache::loncommon::get_env_multiple('form.inststatus');
3582: if (@inststatuses > 0) {
3583: $newinststatus = join(':',map { &escape($_); } @inststatuses);
3584: $changeHash{'inststatus'} = $newinststatus;
3585: if ($newinststatus ne $oldinststatus) {
3586: $changed{'inststatus'} = $newinststatus;
1.378 raeburn 3587: foreach my $name ('portfolio','author') {
3588: ($newdefquota{$name},$newsettingstatus{$name}) =
3589: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3590: }
1.286 raeburn 3591: }
3592: if (ref($usertypes) eq 'HASH') {
1.334 raeburn 3593: $newsettings{'inststatus'} = join(', ',map{ $usertypes->{$_}; } (@inststatuses));
1.286 raeburn 3594: } else {
1.337 raeburn 3595: $newsettings{'inststatus'} = join(', ',@inststatuses);
1.286 raeburn 3596: }
1.334 raeburn 3597: }
3598: } else {
3599: $newinststatus = '';
3600: $changeHash{'inststatus'} = $newinststatus;
3601: $newsettings{'inststatus'} = $othertitle;
3602: if ($newinststatus ne $oldinststatus) {
3603: $changed{'inststatus'} = $changeHash{'inststatus'};
1.378 raeburn 3604: foreach my $name ('portfolio','author') {
3605: ($newdefquota{$name},$newsettingstatus{$name}) =
3606: &Apache::loncommon::default_quota($env{'form.ccdomain'},$newinststatus,$name);
3607: }
1.286 raeburn 3608: }
3609: }
1.334 raeburn 3610: } elsif ($context ne 'selfcreate') {
3611: $canshow{'inststatus'} = 1;
1.337 raeburn 3612: $newsettings{'inststatus'} = $oldsettings{'inststatus'};
1.286 raeburn 3613: }
1.378 raeburn 3614: foreach my $name ('portfolio','author') {
3615: $changeHash{$name.'quota'} = $userenv{$name.'quota'};
3616: }
1.334 raeburn 3617: if ($context eq 'domain') {
1.378 raeburn 3618: foreach my $name ('portfolio','author') {
3619: if ($userenv{$name.'quota'} ne '') {
3620: $oldquota{$name} = $userenv{$name.'quota'};
3621: if ($env{'form.custom_'.$name.'quota'} == 1) {
3622: if ($env{'form.'.$name.'quota'} eq '') {
3623: $newquota{$name} = 0;
3624: } else {
3625: $newquota{$name} = $env{'form.'.$name.'quota'};
3626: $newquota{$name} =~ s/[^\d\.]//g;
3627: }
3628: if ($newquota{$name} != $oldquota{$name}) {
3629: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3630: $changed{$name.'quota'} = 1;
3631: }
3632: }
1.334 raeburn 3633: } else {
1.378 raeburn 3634: if ("a_admin('',\%changeHash,$name)) {
3635: $changed{$name.'quota'} = 1;
3636: $newquota{$name} = $newdefquota{$name};
3637: $newisdefault{$name} = 1;
3638: }
1.334 raeburn 3639: }
1.149 raeburn 3640: } else {
1.378 raeburn 3641: $oldisdefault{$name} = 1;
3642: $oldquota{$name} = $olddefquota{$name};
3643: if ($env{'form.custom_'.$name.'quota'} == 1) {
3644: if ($env{'form.'.$name.'quota'} eq '') {
3645: $newquota{$name} = 0;
3646: } else {
3647: $newquota{$name} = $env{'form.'.$name.'quota'};
3648: $newquota{$name} =~ s/[^\d\.]//g;
3649: }
3650: if ("a_admin($newquota{$name},\%changeHash,$name)) {
3651: $changed{$name.'quota'} = 1;
3652: }
1.334 raeburn 3653: } else {
1.378 raeburn 3654: $newquota{$name} = $newdefquota{$name};
3655: $newisdefault{$name} = 1;
1.334 raeburn 3656: }
1.378 raeburn 3657: }
3658: if ($oldisdefault{$name}) {
3659: $oldsettingstext{'quota'}{$name} = &get_defaultquota_text($oldsettingstatus{$name});
1.383 raeburn 3660: } else {
3661: $oldsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$oldquota{$name});
1.378 raeburn 3662: }
3663: if ($newisdefault{$name}) {
3664: $newsettingstext{'quota'}{$name} = &get_defaultquota_text($newsettingstatus{$name});
1.383 raeburn 3665: } else {
3666: $newsettingstext{'quota'}{$name} = &mt('custom quota: [_1] MB',$newquota{$name});
1.134 raeburn 3667: }
3668: }
1.334 raeburn 3669: &tool_changes('tools',\@usertools,\%oldsettings,\%oldsettingstext,\%userenv,
3670: \%changeHash,\%changed,\%newsettings,\%newsettingstext);
3671: if ($env{'form.ccdomain'} eq $env{'request.role.domain'}) {
3672: &tool_changes('requestcourses',\@requestcourses,\%oldsettings,\%oldsettingstext,
3673: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.406.2.20.2. (raeburn 3674:): my ($isadv,$isauthor) =
3675:): &Apache::lonnet::is_advanced_user($env{'form.ccdomain'},$env{'form.ccuname'});
3676:): unless ($isauthor) {
3677:): &tool_changes('requestauthor',\@requestauthor,\%oldsettings,\%oldsettingstext,
3678:): \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
3679:): }
3680:): &tool_changes('authordefaults',\@authordefaults,\%oldsettings,\%oldsettingstext,
3681:): \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3682: } else {
1.334 raeburn 3683: &tool_changes('reqcrsotherdom',\@requestcourses,\%oldsettings,\%oldsettingstext,
3684: \%userenv,\%changeHash,\%changed,\%newsettings,\%newsettingstext);
1.149 raeburn 3685: }
3686: }
1.334 raeburn 3687: foreach my $item (@userinfo) {
3688: if ($env{'form.c'.$item} ne $userenv{$item}) {
3689: $namechanged{$item} = 1;
3690: }
1.204 raeburn 3691: }
1.378 raeburn 3692: foreach my $name ('portfolio','author') {
1.390 bisitz 3693: $oldsettings{'quota'}{$name} = &mt('[_1] MB',$oldquota{$name});
3694: $newsettings{'quota'}{$name} = &mt('[_1] MB',$newquota{$name});
1.378 raeburn 3695: }
1.334 raeburn 3696: if ((keys(%namechanged) > 0) || (keys(%changed) > 0)) {
1.267 raeburn 3697: my ($chgresult,$namechgresult);
3698: if (keys(%changed) > 0) {
1.406.2.20.2. (raeburn 3699:): $chgresult =
1.204 raeburn 3700: &Apache::lonnet::put('environment',\%changeHash,
3701: $env{'form.ccdomain'},$env{'form.ccuname'});
1.267 raeburn 3702: if ($chgresult eq 'ok') {
1.406.2.20.2. (raeburn 3703:): my ($ca_mgr_del,%ca_mgr_add);
3704:): if ($changed{'managers'}) {
3705:): my (@adds,@dels);
3706:): if ($changeHash{'authormanagers'} eq '') {
3707:): @dels = split(/,/,$userenv{'authormanagers'});
3708:): } elsif ($userenv{'authormanagers'} eq '') {
3709:): @adds = split(/,/,$changeHash{'authormanagers'});
3710:): } else {
3711:): my @old = split(/,/,$userenv{'authormanagers'});
3712:): my @new = split(/,/,$changeHash{'authormanagers'});
3713:): my @diffs = &Apache::loncommon::compare_arrays(\@old,\@new);
3714:): if (@diffs) {
3715:): foreach my $user (@diffs) {
3716:): if (grep(/^\Q$user\E$/,@old)) {
3717:): push(@dels,$user);
3718:): } elsif (grep(/^\Q$user\E$/,@new)) {
3719:): push(@adds,$user);
3720:): }
3721:): }
3722:): }
3723:): }
3724:): my $key = "internal.manager./$env{'form.ccdomain'}/$env{'form.ccuname'}";
3725:): if (@dels) {
3726:): foreach my $user (@dels) {
3727:): if ($user =~ /^($match_username):($match_domain)$/) {
3728:): &Apache::lonnet::del('environment',[$key],$2,$1);
3729:): }
3730:): }
3731:): my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3732:): if (grep(/^\Q$curruser\E$/,@dels)) {
3733:): $ca_mgr_del = $key;
3734:): }
3735:): }
3736:): if (@adds) {
3737:): foreach my $user (@adds) {
3738:): if ($user =~ /^($match_username):($match_domain)$/) {
3739:): &Apache::lonnet::put('environment',{$key => 1},$2,$1);
3740:): }
3741:): }
3742:): my $curruser = $env{'user.name'}.':'.$env{'user.domain'};
3743:): if (grep(/^\Q$curruser\E$/,@adds)) {
3744:): $ca_mgr_add{$key} = 1;
3745:): }
3746:): }
3747:): }
1.267 raeburn 3748: if (($env{'user.name'} eq $env{'form.ccuname'}) &&
3749: ($env{'user.domain'} eq $env{'form.ccdomain'})) {
1.406.2.20.2. (raeburn 3750:): my (%newenvhash,$got_domdefs,%domdefaults,$got_userenv,
3751:): %userenv);
3752:): my @fromenv = keys(%changed);
3753:): push(@fromenv,'inststatus');
1.270 raeburn 3754: foreach my $key (keys(%changed)) {
1.299 raeburn 3755: if (($key eq 'official') || ($key eq 'unofficial')
1.403 raeburn 3756: || ($key eq 'community') || ($key eq 'textbook')) {
1.279 raeburn 3757: $newenvhash{'environment.requestcourses.'.$key} =
3758: $changeHash{'requestcourses.'.$key};
1.362 raeburn 3759: if ($changeHash{'requestcourses.'.$key}) {
1.332 raeburn 3760: $newenvhash{'environment.canrequest.'.$key} = 1;
1.279 raeburn 3761: } else {
1.406.2.20.2. (raeburn 3762:): unless ($got_domdefs) {
3763:): %domdefaults =
3764:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3765:): $got_domdefs = 1;
3766:): }
3767:): unless ($got_userenv) {
3768:): %userenv =
3769:): &Apache::lonnet::userenvironment($env{'user.domain'},
3770:): $env{'user.name'},@fromenv);
3771:): $got_userenv = 1;
3772:): }
1.279 raeburn 3773: $newenvhash{'environment.canrequest.'.$key} =
3774: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3775:): $key,'reload','requestcourses',\%userenv,\%domdefaults);
1.279 raeburn 3776: }
1.362 raeburn 3777: } elsif ($key eq 'requestauthor') {
3778: $newenvhash{'environment.'.$key} = $changeHash{$key};
3779: if ($changeHash{$key}) {
3780: $newenvhash{'environment.canrequest.author'} = 1;
3781: } else {
1.406.2.20.2. (raeburn 3782:): unless ($got_domdefs) {
3783:): %domdefaults =
3784:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3785:): $got_domdefs = 1;
3786:): }
3787:): unless ($got_userenv) {
3788:): %userenv =
3789:): &Apache::lonnet::userenvironment($env{'user.domain'},
3790:): $env{'user.name'},@fromenv);
3791:): $got_userenv = 1;
3792:): }
1.362 raeburn 3793: $newenvhash{'environment.canrequest.author'} =
3794: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3795:): $key,'reload','requestauthor',\%userenv,\%domdefaults);
3796:): }
3797:): } elsif ($key eq 'editors') {
3798:): $newenvhash{'environment.author'.$key} = $changeHash{'author'.$key};
3799:): if ($env{'form.customeditors'}) {
3800:): $newenvhash{'environment.editors'} = $changeHash{'author'.$key};
3801:): } else {
3802:): unless ($got_domdefs) {
3803:): %domdefaults =
3804:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3805:): $got_domdefs = 1;
3806:): }
3807:): if ($domdefaults{'editors'} ne '') {
3808:): $newenvhash{'environment.editors'} = $domdefaults{'editors'};
3809:): } else {
3810:): $newenvhash{'environment.editors'} = 'edit,xml';
3811:): }
1.362 raeburn 3812: }
1.406.2.20.2. (raeburn 3813:): } elsif ($key eq 'archive') {
3814:): $newenvhash{'environment.author.'.$key} =
3815:): $changeHash{'author.'.$key};
3816:): if ($changeHash{'author.'.$key} ne '') {
3817:): $newenvhash{'environment.canarchive'} =
3818:): $changeHash{'author.'.$key};
3819:): } else {
3820:): unless ($got_domdefs) {
3821:): %domdefaults =
3822:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3823:): $got_domdefs = 1;
3824:): }
3825:): $newenvhash{'environment.canarchive'} =
3826:): $domdefaults{'archive'};
3827:): }
1.275 raeburn 3828: } elsif ($key ne 'quota') {
1.270 raeburn 3829: $newenvhash{'environment.tools.'.$key} =
3830: $changeHash{'tools.'.$key};
1.279 raeburn 3831: if ($changeHash{'tools.'.$key} ne '') {
3832: $newenvhash{'environment.availabletools.'.$key} =
3833: $changeHash{'tools.'.$key};
3834: } else {
1.406.2.20.2. (raeburn 3835:): unless ($got_domdefs) {
3836:): %domdefaults =
3837:): &Apache::lonnet::get_domain_defaults($env{'user.domain'});
3838:): $got_domdefs = 1;
3839:): }
3840:): unless ($got_userenv) {
3841:): %userenv =
3842:): &Apache::lonnet::userenvironment($env{'user.domain'},
3843:): $env{'user.name'},@fromenv);
3844:): $got_userenv = 1;
3845:): }
1.279 raeburn 3846: $newenvhash{'environment.availabletools.'.$key} =
1.367 golterma 3847: &Apache::lonnet::usertools_access($env{'user.name'},$env{'user.domain'},
1.406.2.20.2. (raeburn 3848:): $key,'reload','tools',\%userenv,\%domdefaults);
1.279 raeburn 3849: }
1.270 raeburn 3850: }
3851: }
1.271 raeburn 3852: if (keys(%newenvhash)) {
3853: &Apache::lonnet::appenv(\%newenvhash);
3854: }
1.406.2.20.2. (raeburn 3855:): } else {
3856:): if ($ca_mgr_del) {
3857:): &Apache::lonnet::delenv($ca_mgr_del);
3858:): }
3859:): if (keys(%ca_mgr_add)) {
3860:): &Apache::lonnet::appenv(\%ca_mgr_add);
3861:): }
1.267 raeburn 3862: }
1.406.2.20.2. (raeburn 3863:): if ($changed{'aboutme'}) {
3864:): &Apache::loncommon::devalidate_aboutme_cache($env{'form.ccuname'},
3865:): $env{'form.ccdomain'});
3866:): }
1.267 raeburn 3867: }
1.204 raeburn 3868: }
1.334 raeburn 3869: if (keys(%namechanged) > 0) {
1.337 raeburn 3870: foreach my $field (@userinfo) {
3871: $changeHash{$field} = $env{'form.c'.$field};
3872: }
3873: # Make the change
1.204 raeburn 3874: $namechgresult =
3875: &Apache::lonnet::modifyuser($env{'form.ccdomain'},
3876: $env{'form.ccuname'},$changeHash{'id'},undef,undef,
3877: $changeHash{'firstname'},$changeHash{'middlename'},
3878: $changeHash{'lastname'},$changeHash{'generation'},
1.337 raeburn 3879: $changeHash{'id'},undef,$changeHash{'permanentemail'},undef,\@userinfo);
1.220 raeburn 3880: %userupdate = (
3881: lastname => $env{'form.clastname'},
3882: middlename => $env{'form.cmiddlename'},
3883: firstname => $env{'form.cfirstname'},
3884: generation => $env{'form.cgeneration'},
3885: id => $env{'form.cid'},
3886: );
1.204 raeburn 3887: }
1.334 raeburn 3888: if (((keys(%namechanged) > 0) && $namechgresult eq 'ok') ||
1.267 raeburn 3889: ((keys(%changed) > 0) && $chgresult eq 'ok')) {
1.28 matthew 3890: # Tell the user we changed the name
1.334 raeburn 3891: &display_userinfo($r,1,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3892: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,
1.334 raeburn 3893: \%oldsettings, \%oldsettingstext,\%newsettings,
3894: \%newsettingstext);
1.203 raeburn 3895: if ($env{'form.cid'} ne $userenv{'id'}) {
3896: &Apache::lonnet::idput($env{'form.ccdomain'},
1.406.2.5 raeburn 3897: {$env{'form.ccuname'} => $env{'form.cid'}});
1.203 raeburn 3898: if (($recurseid) &&
3899: (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}))) {
3900: my $idresult =
3901: &Apache::lonuserutils::propagate_id_change(
3902: $env{'form.ccuname'},$env{'form.ccdomain'},
3903: \%userupdate);
3904: $r->print('<br />'.$idresult.'<br />');
3905: }
1.196 raeburn 3906: }
1.149 raeburn 3907: if (($env{'form.ccdomain'} eq $env{'user.domain'}) &&
3908: ($env{'form.ccuname'} eq $env{'user.name'})) {
3909: my %newenvhash;
3910: foreach my $key (keys(%changeHash)) {
3911: $newenvhash{'environment.'.$key} = $changeHash{$key};
3912: }
1.238 raeburn 3913: &Apache::lonnet::appenv(\%newenvhash);
1.149 raeburn 3914: }
1.28 matthew 3915: } else { # error occurred
1.389 bisitz 3916: $r->print(
3917: '<p class="LC_error">'
3918: .&mt('Unable to successfully change environment for [_1] in domain [_2].',
3919: '"'.$env{'form.ccuname'}.'"',
3920: '"'.$env{'form.ccdomain'}.'"')
3921: .'</p>');
1.28 matthew 3922: }
1.334 raeburn 3923: } else { # End of if ($env ... ) logic
1.275 raeburn 3924: # They did not want to change the users name, quota, tool availability,
3925: # or ability to request creation of courses,
1.267 raeburn 3926: # but we can still tell them what the name and quota and availabilities are
1.334 raeburn 3927: &display_userinfo($r,undef,\@disporder,\%canshow,\@requestcourses,
1.362 raeburn 3928: \@usertools,\@requestauthor,\%userenv,\%changed,\%namechanged,\%oldsettings,
1.334 raeburn 3929: \%oldsettingstext,\%newsettings,\%newsettingstext);
1.28 matthew 3930: }
1.206 raeburn 3931: if (@mod_disallowed) {
3932: my ($rolestr,$contextname);
3933: if (@longroles > 0) {
3934: $rolestr = join(', ',@longroles);
3935: } else {
3936: $rolestr = &mt('No roles');
3937: }
3938: if ($context eq 'course') {
1.399 bisitz 3939: $contextname = 'course';
1.206 raeburn 3940: } elsif ($context eq 'author') {
1.399 bisitz 3941: $contextname = 'co-author';
1.206 raeburn 3942: }
3943: $r->print(&mt('The following fields were not updated: ').'<ul>');
3944: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
3945: foreach my $field (@mod_disallowed) {
3946: $r->print('<li>'.$fieldtitles{$field}.'</li>'."\n");
3947: }
1.207 raeburn 3948: $r->print('</ul>');
3949: if (@mod_disallowed == 1) {
1.399 bisitz 3950: $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 3951: } else {
1.399 bisitz 3952: $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 3953: }
1.292 bisitz 3954: my $helplink = 'javascript:helpMenu('."'display'".')';
3955: $r->print('<span class="LC_cusr_emph">'.$rolestr.'</span><br />'
3956: .&mt('Please contact your [_1]helpdesk[_2] for more information.'
3957: ,'<a href="'.$helplink.'">','</a>')
3958: .'<br />');
1.206 raeburn 3959: }
1.259 bisitz 3960: $r->print('<span class="LC_warning">'
3961: .$no_forceid_alert
3962: .&Apache::lonuserutils::print_namespacing_alerts($env{'form.ccdomain'},\%alerts,\%curr_rules)
3963: .'</span>');
1.4 www 3964: }
1.367 golterma 3965: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.220 raeburn 3966: if ($env{'form.action'} eq 'singlestudent') {
1.375 raeburn 3967: &enroll_single_student($r,$uhome,$amode,$genpwd,$now,$newuser,$context,
3968: $crstype,$showcredits,$defaultcredits);
1.386 bisitz 3969: my $linktext = ($crstype eq 'Community' ?
3970: &mt('Enroll Another Member') : &mt('Enroll Another Student'));
3971: $r->print(
3972: &Apache::lonhtmlcommon::actionbox([
3973: '<a href="javascript:backPage(document.userupdate)">'
3974: .($crstype eq 'Community' ?
3975: &mt('Enroll Another Member') : &mt('Enroll Another Student'))
3976: .'</a>']));
1.220 raeburn 3977: } else {
1.375 raeburn 3978: my @rolechanges = &update_roles($r,$context,$showcredits);
1.334 raeburn 3979: if (keys(%namechanged) > 0) {
1.220 raeburn 3980: if ($context eq 'course') {
3981: if (@userroles > 0) {
1.225 raeburn 3982: if ((@rolechanges == 0) ||
3983: (!(grep(/^st$/,@rolechanges)))) {
3984: if (grep(/^st$/,@userroles)) {
3985: my $classlistupdated =
3986: &Apache::lonuserutils::update_classlist($cdom,
1.220 raeburn 3987: $cnum,$env{'form.ccdomain'},
3988: $env{'form.ccuname'},\%userupdate);
1.225 raeburn 3989: }
1.220 raeburn 3990: }
3991: }
3992: }
3993: }
1.226 raeburn 3994: my $userinfo = &Apache::loncommon::plainname($env{'form.ccuname'},
1.233 raeburn 3995: $env{'form.ccdomain'});
3996: if ($env{'form.popup'}) {
3997: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
3998: } else {
1.367 golterma 3999: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(['<a href="javascript:backPage(document.userupdate,'."'$env{'form.prevphase'}','modify'".')">'
4000: .&mt('Modify this user: [_1]','<span class="LC_cusr_emph">'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.' ('.$userinfo.')</span>').'</a>',
4001: '<a href="javascript:backPage(document.userupdate)">'.&mt('Create/Modify Another User').'</a>']));
1.233 raeburn 4002: }
1.220 raeburn 4003: }
4004: }
4005:
1.334 raeburn 4006: sub display_userinfo {
1.362 raeburn 4007: my ($r,$changed,$order,$canshow,$requestcourses,$usertools,$requestauthor,
4008: $userenv,$changedhash,$namechangedhash,$oldsetting,$oldsettingtext,
1.334 raeburn 4009: $newsetting,$newsettingtext) = @_;
4010: return unless (ref($order) eq 'ARRAY' &&
4011: ref($canshow) eq 'HASH' &&
4012: ref($requestcourses) eq 'ARRAY' &&
1.362 raeburn 4013: ref($requestauthor) eq 'ARRAY' &&
1.334 raeburn 4014: ref($usertools) eq 'ARRAY' &&
4015: ref($userenv) eq 'HASH' &&
4016: ref($changedhash) eq 'HASH' &&
4017: ref($oldsetting) eq 'HASH' &&
4018: ref($oldsettingtext) eq 'HASH' &&
4019: ref($newsetting) eq 'HASH' &&
4020: ref($newsettingtext) eq 'HASH');
4021: my %lt=&Apache::lonlocal::texthash(
1.372 raeburn 4022: 'ui' => 'User Information',
1.334 raeburn 4023: 'uic' => 'User Information Changed',
4024: 'firstname' => 'First Name',
4025: 'middlename' => 'Middle Name',
4026: 'lastname' => 'Last Name',
4027: 'generation' => 'Generation',
4028: 'id' => 'Student/Employee ID',
4029: 'permanentemail' => 'Permanent e-mail address',
1.378 raeburn 4030: 'portfolioquota' => 'Disk space allocated to portfolio files',
1.385 bisitz 4031: 'authorquota' => 'Disk space allocated to Authoring Space',
1.334 raeburn 4032: 'blog' => 'Blog Availability',
1.361 raeburn 4033: 'webdav' => 'WebDAV Availability',
1.334 raeburn 4034: 'aboutme' => 'Personal Information Page Availability',
4035: 'portfolio' => 'Portfolio Availability',
1.406.2.20.2. (raeburn 4036:): 'portaccess' => 'Portfolio Shareable',
4037:): 'timezone' => 'Can set own Time Zone',
1.334 raeburn 4038: 'official' => 'Can Request Official Courses',
4039: 'unofficial' => 'Can Request Unofficial Courses',
4040: 'community' => 'Can Request Communities',
1.384 raeburn 4041: 'textbook' => 'Can Request Textbook Courses',
1.362 raeburn 4042: 'requestauthor' => 'Can Request Author Role',
1.334 raeburn 4043: 'inststatus' => "Affiliation",
4044: 'prvs' => 'Previous Value:',
1.406.2.20.2. (raeburn 4045:): 'chto' => 'Changed To:',
4046:): 'editors' => "Available Editors in Authoring Space",
4047:): 'managers' => "Co-authors who can add/revoke roles",
4048:): 'archive' => "Managers can download tar.gz file of Authoring Space",
4049:): 'edit' => 'Standard editor (Edit)',
4050:): 'xml' => 'Text editor (EditXML)',
4051:): 'daxe' => 'Daxe editor (Daxe)',
1.334 raeburn 4052: );
4053: if ($changed) {
1.372 raeburn 4054: $r->print('<h3>'.$lt{'uic'}.'</h3>'.
1.367 golterma 4055: &Apache::loncommon::start_data_table().
4056: &Apache::loncommon::start_data_table_header_row());
1.334 raeburn 4057: $r->print("<th> </th>\n");
1.367 golterma 4058: $r->print('<th><b>'.$lt{'prvs'}.'</b></th>');
4059: $r->print('<th><span class="LC_nobreak"><b>'.$lt{'chto'}.'</b></span></th>');
4060: $r->print(&Apache::loncommon::end_data_table_header_row());
4061: my @userinfo = ('firstname','middlename','lastname','generation','permanentemail','id');
4062:
1.334 raeburn 4063: foreach my $item (@userinfo) {
4064: my $value = $env{'form.c'.$item};
1.367 golterma 4065: #show changes only:
1.383 raeburn 4066: unless ($value eq $userenv->{$item}){
1.367 golterma 4067: $r->print(&Apache::loncommon::start_data_table_row());
4068: $r->print("<td>$lt{$item}</td>\n");
1.383 raeburn 4069: $r->print("<td>".$userenv->{$item}."</td>\n");
1.367 golterma 4070: $r->print("<td>$value </td>\n");
4071: $r->print(&Apache::loncommon::end_data_table_row());
1.334 raeburn 4072: }
4073: }
4074: foreach my $entry (@{$order}) {
1.383 raeburn 4075: if ($canshow->{$entry}) {
1.406.2.20.2. (raeburn 4076:): if (($entry eq 'requestcourses') || ($entry eq 'reqcrsotherdom') ||
4077:): ($entry eq 'requestauthor') || ($entry eq 'authordefaults')) {
1.383 raeburn 4078: my @items;
4079: if ($entry eq 'requestauthor') {
4080: @items = ($entry);
1.406.2.20.2. (raeburn 4081:): } elsif ($entry eq 'authordefaults') {
4082:): @items = ('webdav','managers','editors','archive');
1.383 raeburn 4083: } else {
4084: @items = @{$requestcourses};
1.384 raeburn 4085: }
1.383 raeburn 4086: foreach my $item (@items) {
4087: if (($newsetting->{$item} ne $oldsetting->{$item}) ||
4088: ($newsettingtext->{$item} ne $oldsettingtext->{$item})) {
4089: $r->print(&Apache::loncommon::start_data_table_row()."\n");
1.406.2.20.2. (raeburn 4090:): $r->print("<td>$lt{$item}</td><td>\n");
4091:): unless ($item eq 'managers') {
4092:): $r->print($oldsetting->{$item});
4093:): }
1.383 raeburn 4094: if ($oldsettingtext->{$item}) {
4095: if ($oldsetting->{$item}) {
1.406.2.20.2. (raeburn 4096:): unless ($item eq 'managers') {
4097:): $r->print(' -- ');
4098:): }
1.383 raeburn 4099: }
4100: $r->print($oldsettingtext->{$item});
4101: }
1.406.2.20.2. (raeburn 4102:): $r->print("</td>\n<td>");
4103:): unless ($item eq 'managers') {
4104:): $r->print($newsetting->{$item});
4105:): }
1.383 raeburn 4106: if ($newsettingtext->{$item}) {
4107: if ($newsetting->{$item}) {
1.406.2.20.2. (raeburn 4108:): unless ($item eq 'managers') {
4109:): $r->print(' -- ');
4110:): }
1.383 raeburn 4111: }
4112: $r->print($newsettingtext->{$item});
4113: }
4114: $r->print("</td>\n");
4115: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4116: }
4117: }
4118: } elsif ($entry eq 'tools') {
4119: foreach my $item (@{$usertools}) {
1.383 raeburn 4120: if ($newsetting->{$item} ne $oldsetting->{$item}) {
4121: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4122: $r->print("<td>$lt{$item}</td>\n");
4123: $r->print("<td>".$oldsetting->{$item}.' '.$oldsettingtext->{$item}."</td>\n");
4124: $r->print("<td>".$newsetting->{$item}.' '.$newsettingtext->{$item}."</td>\n");
4125: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4126: }
4127: }
1.378 raeburn 4128: } elsif ($entry eq 'quota') {
4129: if ((ref($oldsetting->{$entry}) eq 'HASH') && (ref($oldsettingtext->{$entry}) eq 'HASH') &&
4130: (ref($newsetting->{$entry}) eq 'HASH') && (ref($newsettingtext->{$entry}) eq 'HASH')) {
4131: foreach my $name ('portfolio','author') {
1.383 raeburn 4132: if ($newsetting->{$entry}->{$name} ne $oldsetting->{$entry}->{$name}) {
4133: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4134: $r->print("<td>$lt{$name.$entry}</td>\n");
4135: $r->print("<td>".$oldsettingtext->{$entry}->{$name}."</td>\n");
4136: $r->print("<td>".$newsettingtext->{$entry}->{$name}."</td>\n");
4137: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.378 raeburn 4138: }
4139: }
4140: }
1.334 raeburn 4141: } else {
1.383 raeburn 4142: if ($newsetting->{$entry} ne $oldsetting->{$entry}) {
4143: $r->print(&Apache::loncommon::start_data_table_row()."\n");
4144: $r->print("<td>$lt{$entry}</td>\n");
4145: $r->print("<td>".$oldsetting->{$entry}.' '.$oldsettingtext->{$entry}."</td>\n");
4146: $r->print("<td>".$newsetting->{$entry}.' '.$newsettingtext->{$entry}."</td>\n");
4147: $r->print(&Apache::loncommon::end_data_table_row()."\n");
1.334 raeburn 4148: }
4149: }
4150: }
4151: }
1.367 golterma 4152: $r->print(&Apache::loncommon::end_data_table().'<br />');
1.372 raeburn 4153: } else {
4154: $r->print('<h3>'.$lt{'ui'}.'</h3>'.
4155: '<p>'.&mt('No changes made to user information').'</p>');
1.334 raeburn 4156: }
4157: return;
4158: }
4159:
1.275 raeburn 4160: sub tool_changes {
4161: my ($context,$usertools,$oldaccess,$oldaccesstext,$userenv,$changeHash,
4162: $changed,$newaccess,$newaccesstext) = @_;
4163: if (!((ref($usertools) eq 'ARRAY') && (ref($oldaccess) eq 'HASH') &&
4164: (ref($oldaccesstext) eq 'HASH') && (ref($userenv) eq 'HASH') &&
4165: (ref($changeHash) eq 'HASH') && (ref($changed) eq 'HASH') &&
4166: (ref($newaccess) eq 'HASH') && (ref($newaccesstext) eq 'HASH'))) {
4167: return;
4168: }
1.383 raeburn 4169: my %reqdisplay = &requestchange_display();
1.300 raeburn 4170: if ($context eq 'reqcrsotherdom') {
1.309 raeburn 4171: my @options = ('approval','validate','autolimit');
1.306 raeburn 4172: my $optregex = join('|',@options);
1.300 raeburn 4173: my $cdom = $env{'request.role.domain'};
4174: foreach my $tool (@{$usertools}) {
1.383 raeburn 4175: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
1.314 raeburn 4176: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
1.300 raeburn 4177: $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
1.383 raeburn 4178: my ($newop,$limit);
1.314 raeburn 4179: if ($env{'form.'.$context.'_'.$tool}) {
4180: $newop = $env{'form.'.$context.'_'.$tool};
4181: if ($newop eq 'autolimit') {
1.383 raeburn 4182: $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
1.314 raeburn 4183: $limit =~ s/\D+//g;
4184: $newop .= '='.$limit;
4185: }
4186: }
1.300 raeburn 4187: if ($userenv->{$context.'.'.$tool} eq '') {
1.314 raeburn 4188: if ($newop) {
4189: $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
1.300 raeburn 4190: $changeHash,$context);
4191: if ($changed->{$tool}) {
1.383 raeburn 4192: if ($newop =~ /^autolimit/) {
4193: if ($limit) {
4194: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4195: } else {
4196: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4197: }
4198: } else {
4199: $newaccesstext->{$tool} = $reqdisplay{$newop};
4200: }
1.300 raeburn 4201: } else {
4202: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4203: }
4204: }
4205: } else {
4206: my @curr = split(',',$userenv->{$context.'.'.$tool});
4207: my @new;
4208: my $changedoms;
1.314 raeburn 4209: foreach my $req (@curr) {
4210: if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
4211: my $oldop = $1;
1.383 raeburn 4212: if ($oldop =~ /^autolimit=(\d*)/) {
4213: my $limit = $1;
4214: if ($limit) {
4215: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4216: } else {
4217: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4218: }
4219: } else {
4220: $oldaccesstext->{$tool} = $reqdisplay{$oldop};
4221: }
1.314 raeburn 4222: if ($oldop ne $newop) {
4223: $changedoms = 1;
4224: foreach my $item (@curr) {
4225: my ($reqdom,$option) = split(':',$item);
4226: unless ($reqdom eq $cdom) {
4227: push(@new,$item);
4228: }
4229: }
4230: if ($newop) {
4231: push(@new,$cdom.':'.$newop);
1.300 raeburn 4232: }
1.314 raeburn 4233: @new = sort(@new);
1.300 raeburn 4234: }
1.314 raeburn 4235: last;
1.300 raeburn 4236: }
1.314 raeburn 4237: }
4238: if ((!$changedoms) && ($newop)) {
1.300 raeburn 4239: $changedoms = 1;
1.306 raeburn 4240: @new = sort(@curr,$cdom.':'.$newop);
1.300 raeburn 4241: }
4242: if ($changedoms) {
1.314 raeburn 4243: my $newdomstr;
1.300 raeburn 4244: if (@new) {
4245: $newdomstr = join(',',@new);
4246: }
4247: $changed->{$tool}=&tool_admin($tool,$newdomstr,$changeHash,
4248: $context);
4249: if ($changed->{$tool}) {
4250: if ($env{'form.'.$context.'_'.$tool}) {
1.306 raeburn 4251: if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
1.314 raeburn 4252: my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
4253: $limit =~ s/\D+//g;
4254: if ($limit) {
1.383 raeburn 4255: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
1.314 raeburn 4256: } else {
1.383 raeburn 4257: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
1.306 raeburn 4258: }
1.314 raeburn 4259: } else {
1.306 raeburn 4260: $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
4261: }
1.300 raeburn 4262: } else {
1.383 raeburn 4263: $newaccesstext->{$tool} = &mt("availability set to 'off'");
1.300 raeburn 4264: }
4265: }
4266: }
4267: }
4268: }
4269: return;
4270: }
1.406.2.20.2. (raeburn 4271:): my %tooldesc = &Apache::lonlocal::texthash(
4272:): 'edit' => 'Standard editor (Edit)',
4273:): 'xml' => 'Text editor (EditXML)',
4274:): 'daxe' => 'Daxe editor (Daxe)',
4275:): );
1.275 raeburn 4276: foreach my $tool (@{$usertools}) {
1.383 raeburn 4277: my ($newval,$limit,$envkey);
1.362 raeburn 4278: $envkey = $context.'.'.$tool;
1.306 raeburn 4279: if ($context eq 'requestcourses') {
4280: $newval = $env{'form.crsreq_'.$tool};
4281: if ($newval eq 'autolimit') {
1.383 raeburn 4282: $limit = $env{'form.crsreq_'.$tool.'_limit'};
4283: $limit =~ s/\D+//g;
4284: $newval .= '='.$limit;
1.306 raeburn 4285: }
1.362 raeburn 4286: } elsif ($context eq 'requestauthor') {
4287: $newval = $env{'form.'.$context};
4288: $envkey = $context;
1.406.2.20.2. (raeburn 4289:): } elsif ($context eq 'authordefaults') {
4290:): if ($tool eq 'editors') {
4291:): $envkey = 'authoreditors';
4292:): if ($env{'form.customeditors'} == 1) {
4293:): my @editors;
4294:): my @posseditors = &Apache::loncommon::get_env_multiple('form.custom_editor');
4295:): if (@posseditors) {
4296:): foreach my $editor (@posseditors) {
4297:): if (grep(/^\Q$editor\E$/,@posseditors)) {
4298:): unless (grep(/^\Q$editor\E$/,@editors)) {
4299:): push(@editors,$editor);
4300:): }
4301:): }
4302:): }
4303:): }
4304:): if (@editors) {
4305:): $newval = join(',',(sort(@editors)));
4306:): }
4307:): }
4308:): } elsif ($tool eq 'managers') {
4309:): $envkey = 'authormanagers';
4310:): my @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
4311:): if (@possibles) {
4312:): my %ca_roles = &Apache::lonnet::get_my_roles($env{'form.ccuname'},$env{'form.ccdomain'},
4313:): undef,['active','future'],['ca']);
4314:): if (keys(%ca_roles)) {
4315:): my @custommanagers;
4316:): foreach my $user (@possibles) {
4317:): if ($user =~ /^($match_username):($match_domain)$/) {
4318:): if (exists($ca_roles{$user.':ca'})) {
4319:): unless ($user eq $env{'form.ccuname'}.':'.$env{'form.ccdomain'}) {
4320:): push(@custommanagers,$user);
4321:): }
4322:): }
4323:): }
4324:): }
4325:): if (@custommanagers) {
4326:): $newval = join(',',sort(@custommanagers));
4327:): }
4328:): }
4329:): }
4330:): } elsif ($tool eq 'webdav') {
4331:): $envkey = 'tools.webdav';
4332:): $newval = $env{'form.'.$context.'_'.$tool};
4333:): } elsif ($tool eq 'archive') {
4334:): $envkey = 'authorarchive';
4335:): $newval = $env{'form.'.$context.'_'.$tool};
4336:): }
1.314 raeburn 4337: } else {
1.306 raeburn 4338: $newval = $env{'form.'.$context.'_'.$tool};
4339: }
1.362 raeburn 4340: if ($userenv->{$envkey} ne '') {
1.275 raeburn 4341: $oldaccess->{$tool} = &mt('custom');
1.383 raeburn 4342: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4343: if ($userenv->{$envkey} =~ /^autolimit=(\d*)$/) {
4344: my $currlimit = $1;
4345: if ($currlimit eq '') {
4346: $oldaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4347: } else {
4348: $oldaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$currlimit);
4349: }
4350: } elsif ($userenv->{$envkey}) {
4351: $oldaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
4352: } else {
4353: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4354: }
1.406.2.20.2. (raeburn 4355:): } elsif ($context eq 'authordefaults') {
4356:): if ($tool eq 'managers') {
4357:): if ($userenv->{$envkey} eq '') {
4358:): $oldaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4359:): } else {
4360:): my $managers = $userenv->{$envkey};
4361:): $managers =~ s/,/, /g;
4362:): $oldaccesstext->{$tool} = $managers;
4363:): }
4364:): } elsif ($tool eq 'editors') {
4365:): $oldaccesstext->{$tool} = &mt('can use: [_1]',
4366:): join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4367:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4368:): if ($userenv->{$envkey}) {
4369:): $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4370:): } else {
4371:): $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4372:): }
4373:): }
1.275 raeburn 4374: } else {
1.383 raeburn 4375: if ($userenv->{$envkey}) {
4376: $oldaccesstext->{$tool} = &mt("availability set to 'on'");
4377: } else {
4378: $oldaccesstext->{$tool} = &mt("availability set to 'off'");
4379: }
1.275 raeburn 4380: }
1.362 raeburn 4381: $changeHash->{$envkey} = $userenv->{$envkey};
1.406.2.20.2. (raeburn 4382:): if (($env{'form.custom'.$tool} == 1) ||
4383:): (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.362 raeburn 4384: if ($newval ne $userenv->{$envkey}) {
1.306 raeburn 4385: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4386: $context);
1.275 raeburn 4387: if ($changed->{$tool}) {
4388: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4389: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4390: if ($newval =~ /^autolimit/) {
4391: if ($limit) {
4392: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4393: } else {
4394: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4395: }
4396: } elsif ($newval) {
4397: $newaccesstext->{$tool} = $reqdisplay{$newval};
4398: } else {
4399: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4400: }
1.406.2.20.2. (raeburn 4401:): } elsif ($context eq 'authordefaults') {
4402:): if ($tool eq 'editors') {
4403:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4404:): join(', ', map { $tooldesc{$_} } split(/,/,$changeHash->{$envkey})));
4405:): } elsif ($tool eq 'managers') {
4406:): if ($changeHash->{$envkey} eq '') {
4407:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4408:): } else {
4409:): my $managers = $changeHash->{$envkey};
4410:): $managers =~ s/,/, /g;
4411:): $newaccesstext->{$tool} = $managers;
4412:): }
4413:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4414:): if ($newval) {
4415:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4416:): } else {
4417:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4418:): }
4419:): }
1.275 raeburn 4420: } else {
1.383 raeburn 4421: if ($newval) {
4422: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4423: } else {
4424: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4425: }
1.275 raeburn 4426: }
4427: } else {
4428: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4429: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.406.2.20.2. (raeburn 4430:): if ($userenv->{$envkey} =~ /^autolimit/) {
1.383 raeburn 4431: if ($limit) {
4432: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4433: } else {
4434: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4435: }
1.406.2.20.2. (raeburn 4436:): } elsif ($userenv->{$envkey}) {
4437:): $newaccesstext->{$tool} = $reqdisplay{$userenv->{$envkey}};
1.383 raeburn 4438: } else {
4439: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4440: }
1.406.2.20.2. (raeburn 4441:): } elsif ($context eq 'authordefaults') {
4442:): if ($tool eq 'editors') {
4443:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4444:): join(', ', map { $tooldesc{$_} } split(/,/,$userenv->{$envkey})));
4445:): } elsif ($tool eq 'managers') {
4446:): if ($userenv->{$envkey} eq '') {
4447:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4448:): } else {
4449:): my $managers = $userenv->{$envkey};
4450:): $managers =~ s/,/, /g;
4451:): $newaccesstext->{$tool} = $managers;
4452:): }
4453:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4454:): if ($userenv->{$envkey}) {
4455:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4456:): } else {
4457:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4458:): }
4459:): }
1.275 raeburn 4460: } else {
1.383 raeburn 4461: if ($userenv->{$context.'.'.$tool}) {
4462: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4463: } else {
4464: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4465: }
1.275 raeburn 4466: }
4467: }
4468: } else {
4469: $newaccess->{$tool} = $oldaccess->{$tool};
4470: $newaccesstext->{$tool} = $oldaccesstext->{$tool};
4471: }
4472: } else {
4473: $changed->{$tool} = &tool_admin($tool,'',$changeHash,$context);
4474: if ($changed->{$tool}) {
4475: $newaccess->{$tool} = &mt('default');
4476: } else {
4477: $newaccess->{$tool} = $oldaccess->{$tool};
1.383 raeburn 4478: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4479: if ($newval =~ /^autolimit/) {
4480: if ($limit) {
4481: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4482: } else {
4483: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4484: }
4485: } elsif ($newval) {
4486: $newaccesstext->{$tool} = $reqdisplay{$newval};
4487: } else {
4488: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4489: }
1.406.2.20.2. (raeburn 4490:): } elsif ($context eq 'authordefaults') {
4491:): if ($tool eq 'editors') {
4492:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4493:): join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4494:): } elsif ($tool eq 'managers') {
4495:): if ($newval eq '') {
4496:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4497:): } else {
4498:): my $managers = $newval;
4499:): $managers =~ s/,/, /g;
4500:): $newaccesstext->{$tool} = $managers;
4501:): }
4502:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4503:): if ($newval) {
4504:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4505:): } else {
4506:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4507:): }
4508:): }
1.275 raeburn 4509: } else {
1.383 raeburn 4510: if ($userenv->{$context.'.'.$tool}) {
4511: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4512: } else {
4513: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4514: }
1.275 raeburn 4515: }
4516: }
4517: }
4518: } else {
4519: $oldaccess->{$tool} = &mt('default');
1.406.2.20.2. (raeburn 4520:): if (($env{'form.custom'.$tool} == 1) ||
4521:): (($context eq 'authordefaults') && ($tool eq 'managers') && ($newval ne ''))) {
1.306 raeburn 4522: $changed->{$tool} = &tool_admin($tool,$newval,$changeHash,
4523: $context);
1.275 raeburn 4524: if ($changed->{$tool}) {
4525: $newaccess->{$tool} = &mt('custom');
1.383 raeburn 4526: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
4527: if ($newval =~ /^autolimit/) {
4528: if ($limit) {
4529: $newaccesstext->{$tool} = &mt('available with automatic approval, up to limit of [quant,_1,request] per user',$limit);
4530: } else {
4531: $newaccesstext->{$tool} = &mt('available with automatic approval (unlimited)');
4532: }
4533: } elsif ($newval) {
4534: $newaccesstext->{$tool} = $reqdisplay{$newval};
4535: } else {
4536: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4537: }
1.406.2.20.2. (raeburn 4538:): } elsif ($context eq 'authordefaults') {
4539:): if ($tool eq 'managers') {
4540:): if ($newval eq '') {
4541:): $newaccesstext->{$tool} = &mt('Only author may manage co-author roles');
4542:): } else {
4543:): my $managers = $newval;
4544:): $managers =~ s/,/, /g;
4545:): $newaccesstext->{$tool} = $managers;
4546:): }
4547:): } elsif ($tool eq 'editors') {
4548:): $newaccesstext->{$tool} = &mt('can use: [_1]',
4549:): join(', ', map { $tooldesc{$_} } split(/,/,$newval)));
4550:): } elsif (($tool eq 'webdav') || ($tool eq 'archive')) {
4551:): if ($newval) {
4552:): $newaccesstext->{$tool} = &mt("availability set to 'on'");
4553:): } else {
4554:): $newaccesstext->{$tool} = &mt("availability set to 'off'");
4555:): }
4556:): }
1.275 raeburn 4557: } else {
1.383 raeburn 4558: if ($newval) {
4559: $newaccesstext->{$tool} = &mt("availability set to 'on'");
4560: } else {
4561: $newaccesstext->{$tool} = &mt("availability set to 'off'");
4562: }
1.275 raeburn 4563: }
4564: } else {
4565: $newaccess->{$tool} = $oldaccess->{$tool};
4566: }
4567: } else {
4568: $newaccess->{$tool} = $oldaccess->{$tool};
4569: }
4570: }
4571: }
4572: return;
4573: }
4574:
1.220 raeburn 4575: sub update_roles {
1.375 raeburn 4576: my ($r,$context,$showcredits) = @_;
1.4 www 4577: my $now=time;
1.225 raeburn 4578: my @rolechanges;
1.220 raeburn 4579: my %disallowed;
1.73 sakharuk 4580: $r->print('<h3>'.&mt('Modifying Roles').'</h3>');
1.404 raeburn 4581: foreach my $key (keys(%env)) {
1.135 raeburn 4582: next if (! $env{$key});
1.190 raeburn 4583: next if ($key eq 'form.action');
1.27 matthew 4584: # Revoke roles
1.135 raeburn 4585: if ($key=~/^form\.rev/) {
4586: if ($key=~/^form\.rev\:([^\_]+)\_([^\_\.]+)$/) {
1.64 www 4587: # Revoke standard role
1.170 albertel 4588: my ($scope,$role) = ($1,$2);
4589: my $result =
4590: &Apache::lonnet::revokerole($env{'form.ccdomain'},
4591: $env{'form.ccuname'},
1.239 raeburn 4592: $scope,$role,'','',$context);
1.367 golterma 4593: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4594: &mt('Revoking [_1] in [_2]',
4595: &Apache::lonnet::plaintext($role),
1.372 raeburn 4596: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4597: $result ne "ok").'<br />');
4598: if ($result ne "ok") {
4599: $r->print(&mt('Error: [_1]',$result).'<br />');
4600: }
1.170 albertel 4601: if ($role eq 'st') {
1.202 raeburn 4602: my $result =
1.198 raeburn 4603: &Apache::lonuserutils::classlist_drop($scope,
4604: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4605: $now);
1.367 golterma 4606: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.53 www 4607: }
1.225 raeburn 4608: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4609: push(@rolechanges,$role);
4610: }
1.196 raeburn 4611: }
1.195 raeburn 4612: if ($key=~m{^form\.rev\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}s) {
1.64 www 4613: # Revoke custom role
1.369 bisitz 4614: my $result = &Apache::lonnet::revokecustomrole(
4615: $env{'form.ccdomain'},$env{'form.ccuname'},$1,$2,$3,$4,'','',$context);
1.367 golterma 4616: $r->print(&Apache::lonhtmlcommon::confirm_success(
1.369 bisitz 4617: &mt('Revoking custom role [_1] by [_2] in [_3]',
1.372 raeburn 4618: $4,$3.':'.$2,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4619: $result ne 'ok').'<br />');
4620: if ($result ne "ok") {
4621: $r->print(&mt('Error: [_1]',$result).'<br />');
4622: }
1.225 raeburn 4623: if (!grep(/^cr$/,@rolechanges)) {
4624: push(@rolechanges,'cr');
4625: }
1.64 www 4626: }
1.135 raeburn 4627: } elsif ($key=~/^form\.del/) {
4628: if ($key=~/^form\.del\:([^\_]+)\_([^\_\.]+)$/) {
1.116 raeburn 4629: # Delete standard role
1.170 albertel 4630: my ($scope,$role) = ($1,$2);
4631: my $result =
4632: &Apache::lonnet::assignrole($env{'form.ccdomain'},
4633: $env{'form.ccuname'},
1.239 raeburn 4634: $scope,$role,$now,0,1,'',
4635: $context);
1.367 golterma 4636: $r->print(&Apache::lonhtmlcommon::confirm_success(
4637: &mt('Deleting [_1] in [_2]',
1.369 bisitz 4638: &Apache::lonnet::plaintext($role),
1.372 raeburn 4639: &Apache::loncommon::show_role_extent($scope,$context,$role)),
1.369 bisitz 4640: $result ne 'ok').'<br />');
4641: if ($result ne "ok") {
4642: $r->print(&mt('Error: [_1]',$result).'<br />');
4643: }
1.367 golterma 4644:
1.170 albertel 4645: if ($role eq 'st') {
1.202 raeburn 4646: my $result =
1.198 raeburn 4647: &Apache::lonuserutils::classlist_drop($scope,
4648: $env{'form.ccuname'},$env{'form.ccdomain'},
1.202 raeburn 4649: $now);
1.369 bisitz 4650: $r->print(&Apache::lonhtmlcommon::confirm_success($result));
1.81 albertel 4651: }
1.225 raeburn 4652: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4653: push(@rolechanges,$role);
4654: }
1.116 raeburn 4655: }
1.139 albertel 4656: if ($key=~m{^form\.del\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4657: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4658: # Delete custom role
1.369 bisitz 4659: my $result =
4660: &Apache::lonnet::assigncustomrole($env{'form.ccdomain'},
4661: $env{'form.ccuname'},$url,$rdom,$rnam,$rolename,$now,
4662: 0,1,$context);
4663: $r->print(&Apache::lonhtmlcommon::confirm_success(&mt('Deleting custom role [_1] by [_2] in [_3]',
1.372 raeburn 4664: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4665: $result ne "ok").'<br />');
4666: if ($result ne "ok") {
4667: $r->print(&mt('Error: [_1]',$result).'<br />');
4668: }
1.367 golterma 4669:
1.225 raeburn 4670: if (!grep(/^cr$/,@rolechanges)) {
4671: push(@rolechanges,'cr');
4672: }
1.116 raeburn 4673: }
1.135 raeburn 4674: } elsif ($key=~/^form\.ren/) {
1.101 albertel 4675: my $udom = $env{'form.ccdomain'};
4676: my $uname = $env{'form.ccuname'};
1.116 raeburn 4677: # Re-enable standard role
1.135 raeburn 4678: if ($key=~/^form\.ren\:([^\_]+)\_([^\_\.]+)$/) {
1.89 raeburn 4679: my $url = $1;
4680: my $role = $2;
4681: my $logmsg;
4682: my $output;
4683: if ($role eq 'st') {
1.141 albertel 4684: if ($url =~ m-^/($match_domain)/($match_courseid)/?(\w*)$-) {
1.374 raeburn 4685: my ($cdom,$cnum,$csec) = ($1,$2,$3);
1.375 raeburn 4686: my $credits;
4687: if ($showcredits) {
4688: my $defaultcredits =
4689: &Apache::lonuserutils::get_defaultcredits($cdom,$cnum);
4690: $credits = &get_user_credits($defaultcredits,$cdom,$cnum);
4691: }
4692: my $result = &Apache::loncommon::commit_studentrole(\$logmsg,$udom,$uname,$url,$role,$now,0,$cdom,$cnum,$csec,$context,$credits);
1.220 raeburn 4693: if (($result =~ /^error/) || ($result eq 'not_in_class') || ($result eq 'unknown_course') || ($result eq 'refused')) {
1.223 raeburn 4694: if ($result eq 'refused' && $logmsg) {
4695: $output = $logmsg;
4696: } else {
1.369 bisitz 4697: $output = &mt('Error: [_1]',$result)."\n";
1.223 raeburn 4698: }
1.89 raeburn 4699: } else {
1.372 raeburn 4700: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Assigning [_1] in [_2] starting [_3]',
4701: &Apache::lonnet::plaintext($role),
4702: &Apache::loncommon::show_role_extent($url,$context,'st'),
4703: &Apache::lonlocal::locallocaltime($now))).'<br />'.$logmsg.'<br />';
1.89 raeburn 4704: }
4705: }
4706: } else {
1.101 albertel 4707: my $result=&Apache::lonnet::assignrole($env{'form.ccdomain'},
1.239 raeburn 4708: $env{'form.ccuname'},$url,$role,0,$now,'','',
4709: $context);
1.367 golterma 4710: $output = &Apache::lonhtmlcommon::confirm_success(&mt('Re-enabling [_1] in [_2]',
1.372 raeburn 4711: &Apache::lonnet::plaintext($role),
4712: &Apache::loncommon::show_role_extent($url,$context,$role)),$result ne "ok").'<br />';
1.369 bisitz 4713: if ($result ne "ok") {
4714: $output .= &mt('Error: [_1]',$result).'<br />';
4715: }
4716: }
1.89 raeburn 4717: $r->print($output);
1.225 raeburn 4718: if (!grep(/^\Q$role\E$/,@rolechanges)) {
4719: push(@rolechanges,$role);
4720: }
1.113 raeburn 4721: }
1.116 raeburn 4722: # Re-enable custom role
1.139 albertel 4723: if ($key=~m{^form\.ren\:([^_]+)_cr\.cr/($match_domain)/($match_username)/(\w+)$}) {
1.116 raeburn 4724: my ($url,$rdom,$rnam,$rolename) = ($1,$2,$3,$4);
4725: my $result = &Apache::lonnet::assigncustomrole(
4726: $env{'form.ccdomain'}, $env{'form.ccuname'},
1.240 raeburn 4727: $url,$rdom,$rnam,$rolename,0,$now,undef,$context);
1.369 bisitz 4728: $r->print(&Apache::lonhtmlcommon::confirm_success(
4729: &mt('Re-enabling custom role [_1] by [_2] in [_3]',
1.372 raeburn 4730: $rolename,$rnam.':'.$rdom,&Apache::loncommon::show_role_extent($1,$context,'cr')),
1.369 bisitz 4731: $result ne "ok").'<br />');
4732: if ($result ne "ok") {
4733: $r->print(&mt('Error: [_1]',$result).'<br />');
4734: }
1.225 raeburn 4735: if (!grep(/^cr$/,@rolechanges)) {
4736: push(@rolechanges,'cr');
4737: }
1.116 raeburn 4738: }
1.135 raeburn 4739: } elsif ($key=~/^form\.act/) {
1.101 albertel 4740: my $udom = $env{'form.ccdomain'};
4741: my $uname = $env{'form.ccuname'};
1.141 albertel 4742: if ($key=~/^form\.act\_($match_domain)\_($match_courseid)\_cr_cr_($match_domain)_($match_username)_([^\_]+)$/) {
1.65 www 4743: # Activate a custom role
1.83 albertel 4744: my ($one,$two,$three,$four,$five)=($1,$2,$3,$4,$5);
4745: my $url='/'.$one.'/'.$two;
4746: my $full=$one.'_'.$two.'_cr_cr_'.$three.'_'.$four.'_'.$five;
1.65 www 4747:
1.101 albertel 4748: my $start = ( $env{'form.start_'.$full} ?
4749: $env{'form.start_'.$full} :
1.88 raeburn 4750: $now );
1.101 albertel 4751: my $end = ( $env{'form.end_'.$full} ?
4752: $env{'form.end_'.$full} :
1.88 raeburn 4753: 0 );
4754:
4755: # split multiple sections
4756: my %sections = ();
1.101 albertel 4757: my $num_sections = &build_roles($env{'form.sec_'.$full},\%sections,$5);
1.88 raeburn 4758: if ($num_sections == 0) {
1.240 raeburn 4759: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$url,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4760: } else {
1.114 albertel 4761: my %curr_groups =
1.117 raeburn 4762: &Apache::longroup::coursegroups($one,$two);
1.404 raeburn 4763: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.113 raeburn 4764: if (($sec eq 'none') || ($sec eq 'all') ||
4765: exists($curr_groups{$sec})) {
4766: $disallowed{$sec} = $url;
4767: next;
4768: }
4769: my $securl = $url.'/'.$sec;
1.240 raeburn 4770: $r->print(&Apache::loncommon::commit_customrole($udom,$uname,$securl,$three,$four,$five,$start,$end,$context));
1.88 raeburn 4771: }
4772: }
1.225 raeburn 4773: if (!grep(/^cr$/,@rolechanges)) {
4774: push(@rolechanges,'cr');
4775: }
1.142 raeburn 4776: } elsif ($key=~/^form\.act\_($match_domain)\_($match_name)\_([^\_]+)$/) {
1.27 matthew 4777: # Activate roles for sections with 3 id numbers
4778: # set start, end times, and the url for the class
1.83 albertel 4779: my ($one,$two,$three)=($1,$2,$3);
1.101 albertel 4780: my $start = ( $env{'form.start_'.$one.'_'.$two.'_'.$three} ?
4781: $env{'form.start_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4782: $now );
1.101 albertel 4783: my $end = ( $env{'form.end_'.$one.'_'.$two.'_'.$three} ?
4784: $env{'form.end_'.$one.'_'.$two.'_'.$three} :
1.27 matthew 4785: 0 );
1.83 albertel 4786: my $url='/'.$one.'/'.$two;
1.88 raeburn 4787: my $type = 'three';
4788: # split multiple sections
4789: my %sections = ();
1.101 albertel 4790: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
1.375 raeburn 4791: my $credits;
4792: if ($three eq 'st') {
4793: if ($showcredits) {
4794: my $defaultcredits =
4795: &Apache::lonuserutils::get_defaultcredits($one,$two);
4796: $credits = $env{'form.credits_'.$one.'_'.$two.'_'.$three};
4797: $credits =~ s/[^\d\.]//g;
4798: if ($credits eq $defaultcredits) {
4799: undef($credits);
4800: }
4801: }
4802: }
1.88 raeburn 4803: if ($num_sections == 0) {
1.375 raeburn 4804: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4805: } else {
1.114 albertel 4806: my %curr_groups =
1.117 raeburn 4807: &Apache::longroup::coursegroups($one,$two);
1.88 raeburn 4808: my $emptysec = 0;
1.404 raeburn 4809: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4810: $sec =~ s/\W//g;
1.113 raeburn 4811: if ($sec ne '') {
4812: if (($sec eq 'none') || ($sec eq 'all') ||
4813: exists($curr_groups{$sec})) {
4814: $disallowed{$sec} = $url;
4815: next;
4816: }
1.88 raeburn 4817: my $securl = $url.'/'.$sec;
1.375 raeburn 4818: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$three,$start,$end,$one,$two,$sec,$context,$credits));
1.88 raeburn 4819: } else {
4820: $emptysec = 1;
4821: }
4822: }
4823: if ($emptysec) {
1.375 raeburn 4824: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$three,$start,$end,$one,$two,'',$context,$credits));
1.88 raeburn 4825: }
1.225 raeburn 4826: }
4827: if (!grep(/^\Q$three\E$/,@rolechanges)) {
4828: push(@rolechanges,$three);
4829: }
1.135 raeburn 4830: } elsif ($key=~/^form\.act\_([^\_]+)\_([^\_]+)$/) {
1.27 matthew 4831: # Activate roles for sections with two id numbers
4832: # set start, end times, and the url for the class
1.101 albertel 4833: my $start = ( $env{'form.start_'.$1.'_'.$2} ?
4834: $env{'form.start_'.$1.'_'.$2} :
1.27 matthew 4835: $now );
1.101 albertel 4836: my $end = ( $env{'form.end_'.$1.'_'.$2} ?
4837: $env{'form.end_'.$1.'_'.$2} :
1.27 matthew 4838: 0 );
1.225 raeburn 4839: my $one = $1;
4840: my $two = $2;
4841: my $url='/'.$one.'/';
1.88 raeburn 4842: # split multiple sections
4843: my %sections = ();
1.225 raeburn 4844: my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two},\%sections,$two);
1.88 raeburn 4845: if ($num_sections == 0) {
1.240 raeburn 4846: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4847: } else {
4848: my $emptysec = 0;
1.404 raeburn 4849: foreach my $sec (sort {$a cmp $b} keys(%sections)) {
1.88 raeburn 4850: if ($sec ne '') {
4851: my $securl = $url.'/'.$sec;
1.240 raeburn 4852: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$securl,$two,$start,$end,$one,undef,$sec,$context));
1.88 raeburn 4853: } else {
4854: $emptysec = 1;
4855: }
4856: }
4857: if ($emptysec) {
1.240 raeburn 4858: $r->print(&Apache::loncommon::commit_standardrole($udom,$uname,$url,$two,$start,$end,$one,undef,'',$context));
1.88 raeburn 4859: }
4860: }
1.225 raeburn 4861: if (!grep(/^\Q$two\E$/,@rolechanges)) {
4862: push(@rolechanges,$two);
4863: }
1.64 www 4864: } else {
1.190 raeburn 4865: $r->print('<p><span class="LC_error">'.&mt('ERROR').': '.&mt('Unknown command').' <tt>'.$key.'</tt></span></p><br />');
1.64 www 4866: }
1.113 raeburn 4867: foreach my $key (sort(keys(%disallowed))) {
1.274 bisitz 4868: $r->print('<p class="LC_warning">');
1.113 raeburn 4869: if (($key eq 'none') || ($key eq 'all')) {
1.274 bisitz 4870: $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 4871: } else {
1.274 bisitz 4872: $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 4873: }
1.274 bisitz 4874: $r->print('</p><p>'
4875: .&mt('Please [_1]go back[_2] and choose a different section name.'
4876: ,'<a href="javascript:history.go(-1)'
4877: ,'</a>')
4878: .'</p><br />'
4879: );
1.113 raeburn 4880: }
4881: }
1.101 albertel 4882: } # End of foreach (keys(%env))
1.75 www 4883: # Flush the course logs so reverse user roles immediately updated
1.349 raeburn 4884: $r->register_cleanup(\&Apache::lonnet::flushcourselogs);
1.225 raeburn 4885: if (@rolechanges == 0) {
1.372 raeburn 4886: $r->print('<p>'.&mt('No roles to modify').'</p>');
1.193 raeburn 4887: }
1.225 raeburn 4888: return @rolechanges;
1.220 raeburn 4889: }
4890:
1.375 raeburn 4891: sub get_user_credits {
4892: my ($uname,$udom,$defaultcredits,$cdom,$cnum) = @_;
4893: if ($cdom eq '' || $cnum eq '') {
4894: return unless ($env{'request.course.id'});
4895: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4896: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4897: }
4898: my $credits;
4899: my %currhash =
4900: &Apache::lonnet::get('classlist',[$uname.':'.$udom],$cdom,$cnum);
4901: if (keys(%currhash) > 0) {
4902: my @items = split(/:/,$currhash{$uname.':'.$udom});
4903: my $crdidx = &Apache::loncoursedata::CL_CREDITS() - 3;
4904: $credits = $items[$crdidx];
4905: $credits =~ s/[^\d\.]//g;
4906: }
4907: if ($credits eq $defaultcredits) {
4908: undef($credits);
4909: }
4910: return $credits;
4911: }
4912:
1.220 raeburn 4913: sub enroll_single_student {
1.375 raeburn 4914: my ($r,$uhome,$amode,$genpwd,$now,$newuser,$context,$crstype,
4915: $showcredits,$defaultcredits) = @_;
1.318 raeburn 4916: $r->print('<h3>');
4917: if ($crstype eq 'Community') {
4918: $r->print(&mt('Enrolling Member'));
4919: } else {
4920: $r->print(&mt('Enrolling Student'));
4921: }
4922: $r->print('</h3>');
1.220 raeburn 4923:
4924: # Remove non alphanumeric values from section
4925: $env{'form.sections'}=~s/\W//g;
4926:
1.375 raeburn 4927: my $credits;
4928: if (($showcredits) && ($env{'form.credits'} ne '')) {
4929: $credits = $env{'form.credits'};
4930: $credits =~ s/[^\d\.]//g;
4931: if ($credits ne '') {
4932: if ($credits eq $defaultcredits) {
4933: undef($credits);
4934: }
4935: }
4936: }
4937:
1.220 raeburn 4938: # Clean out any old student roles the user has in this class.
4939: &Apache::lonuserutils::modifystudent($env{'form.ccdomain'},
4940: $env{'form.ccuname'},$env{'request.course.id'},undef,$uhome);
4941: my ($startdate,$enddate) = &Apache::lonuserutils::get_dates_from_form();
4942: my $enroll_result =
4943: &Apache::lonnet::modify_student_enrollment($env{'form.ccdomain'},
4944: $env{'form.ccuname'},$env{'form.cid'},$env{'form.cfirstname'},
4945: $env{'form.cmiddlename'},$env{'form.clastname'},
4946: $env{'form.generation'},$env{'form.sections'},$enddate,
1.375 raeburn 4947: $startdate,'manual',undef,$env{'request.course.id'},'',$context,
4948: $credits);
1.220 raeburn 4949: if ($enroll_result =~ /^ok/) {
1.381 bisitz 4950: $r->print(&mt('[_1] enrolled','<b>'.$env{'form.ccuname'}.':'.$env{'form.ccdomain'}.'</b>'));
1.220 raeburn 4951: if ($env{'form.sections'} ne '') {
4952: $r->print(' '.&mt('in section [_1]',$env{'form.sections'}));
4953: }
4954: my ($showstart,$showend);
4955: if ($startdate <= $now) {
4956: $showstart = &mt('Access starts immediately');
4957: } else {
4958: $showstart = &mt('Access starts: ').&Apache::lonlocal::locallocaltime($startdate);
4959: }
4960: if ($enddate == 0) {
4961: $showend = &mt('ends: no ending date');
4962: } else {
4963: $showend = &mt('ends: ').&Apache::lonlocal::locallocaltime($enddate);
4964: }
4965: $r->print('.<br />'.$showstart.'; '.$showend);
4966: if ($startdate <= $now && !$newuser) {
1.386 bisitz 4967: $r->print('<p class="LC_info">');
1.318 raeburn 4968: if ($crstype eq 'Community') {
1.392 raeburn 4969: $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 4970: } else {
1.392 raeburn 4971: $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 4972: }
4973: $r->print('</p>');
1.220 raeburn 4974: }
4975: } else {
4976: $r->print(&mt('unable to enroll').": ".$enroll_result);
4977: }
4978: return;
1.188 raeburn 4979: }
4980:
1.204 raeburn 4981: sub get_defaultquota_text {
4982: my ($settingstatus) = @_;
4983: my $defquotatext;
4984: if ($settingstatus eq '') {
1.383 raeburn 4985: $defquotatext = &mt('default');
1.204 raeburn 4986: } else {
4987: my ($usertypes,$order) =
4988: &Apache::lonnet::retrieve_inst_usertypes($env{'form.ccdomain'});
4989: if ($usertypes->{$settingstatus} eq '') {
1.383 raeburn 4990: $defquotatext = &mt('default');
1.204 raeburn 4991: } else {
1.383 raeburn 4992: $defquotatext = &mt('default for [_1]',$usertypes->{$settingstatus});
1.204 raeburn 4993: }
4994: }
4995: return $defquotatext;
4996: }
4997:
1.188 raeburn 4998: sub update_result_form {
4999: my ($uhome) = @_;
5000: my $outcome =
1.367 golterma 5001: '<form name="userupdate" method="post" action="">'."\n";
1.160 raeburn 5002: foreach my $item ('srchby','srchin','srchtype','srchterm','srchdomain','ccuname','ccdomain') {
1.188 raeburn 5003: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5004: }
1.207 raeburn 5005: if ($env{'form.origname'} ne '') {
5006: $outcome .= '<input type="hidden" name="origname" value="'.$env{'form.origname'}.'" />'."\n";
5007: }
1.160 raeburn 5008: foreach my $item ('sortby','seluname','seludom') {
5009: if (exists($env{'form.'.$item})) {
1.188 raeburn 5010: $outcome .= '<input type="hidden" name="'.$item.'" value="'.$env{'form.'.$item}.'" />'."\n";
1.160 raeburn 5011: }
5012: }
1.188 raeburn 5013: if ($uhome eq 'no_host') {
5014: $outcome .= '<input type="hidden" name="forcenewuser" value="1" />'."\n";
5015: }
5016: $outcome .= '<input type="hidden" name="phase" value="" />'."\n".
1.383 raeburn 5017: '<input type="hidden" name="currstate" value="" />'."\n".
5018: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
1.188 raeburn 5019: '</form>';
5020: return $outcome;
1.4 www 5021: }
5022:
1.149 raeburn 5023: sub quota_admin {
1.378 raeburn 5024: my ($setquota,$changeHash,$name) = @_;
1.149 raeburn 5025: my $quotachanged;
5026: if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
5027: # Current user has quota modification privileges
1.267 raeburn 5028: if (ref($changeHash) eq 'HASH') {
5029: $quotachanged = 1;
1.378 raeburn 5030: $changeHash->{$name.'quota'} = $setquota;
1.267 raeburn 5031: }
1.149 raeburn 5032: }
5033: return $quotachanged;
5034: }
5035:
1.267 raeburn 5036: sub tool_admin {
1.275 raeburn 5037: my ($tool,$settool,$changeHash,$context) = @_;
5038: my $canchange = 0;
1.279 raeburn 5039: if ($context eq 'requestcourses') {
1.275 raeburn 5040: if (&Apache::lonnet::allowed('ccc',$env{'form.ccdomain'})) {
5041: $canchange = 1;
5042: }
1.300 raeburn 5043: } elsif ($context eq 'reqcrsotherdom') {
5044: if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
5045: $canchange = 1;
5046: }
1.362 raeburn 5047: } elsif ($context eq 'requestauthor') {
5048: if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5049: $canchange = 1;
5050: }
1.406.2.20.2. (raeburn 5051:): } elsif ($context eq 'authordefaults') {
5052:): if (&Apache::lonnet::allowed('cau',$env{'request.role.domain'})) {
5053:): $canchange = 1;
5054:): }
1.275 raeburn 5055: } elsif (&Apache::lonnet::allowed('mut',$env{'form.ccdomain'})) {
5056: # Current user has quota modification privileges
5057: $canchange = 1;
5058: }
1.267 raeburn 5059: my $toolchanged;
1.275 raeburn 5060: if ($canchange) {
1.267 raeburn 5061: if (ref($changeHash) eq 'HASH') {
5062: $toolchanged = 1;
1.362 raeburn 5063: if ($tool eq 'requestauthor') {
5064: $changeHash->{$context} = $settool;
1.406.2.20.2. (raeburn 5065:): } elsif (($tool eq 'managers') || ($tool eq 'editors') || ($tool eq 'archive')) {
5066:): $changeHash->{'author'.$tool} = $settool;
5067:): } elsif ($tool eq 'webdav') {
5068:): $changeHash->{'tools.'.$tool} = $settool;
1.362 raeburn 5069: } else {
5070: $changeHash->{$context.'.'.$tool} = $settool;
5071: }
1.267 raeburn 5072: }
5073: }
5074: return $toolchanged;
5075: }
5076:
1.88 raeburn 5077: sub build_roles {
1.89 raeburn 5078: my ($sectionstr,$sections,$role) = @_;
1.88 raeburn 5079: my $num_sections = 0;
5080: if ($sectionstr=~ /,/) {
5081: my @secnums = split/,/,$sectionstr;
1.89 raeburn 5082: if ($role eq 'st') {
5083: $secnums[0] =~ s/\W//g;
5084: $$sections{$secnums[0]} = 1;
5085: $num_sections = 1;
5086: } else {
5087: foreach my $sec (@secnums) {
5088: $sec =~ ~s/\W//g;
1.150 banghart 5089: if (!($sec eq "")) {
1.89 raeburn 5090: if (exists($$sections{$sec})) {
5091: $$sections{$sec} ++;
5092: } else {
5093: $$sections{$sec} = 1;
5094: $num_sections ++;
5095: }
1.88 raeburn 5096: }
5097: }
5098: }
5099: } else {
5100: $sectionstr=~s/\W//g;
5101: unless ($sectionstr eq '') {
5102: $$sections{$sectionstr} = 1;
5103: $num_sections ++;
5104: }
5105: }
1.129 albertel 5106:
1.88 raeburn 5107: return $num_sections;
5108: }
5109:
1.58 www 5110: # ========================================================== Custom Role Editor
5111:
5112: sub custom_role_editor {
1.406.2.14 raeburn 5113: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.324 raeburn 5114: my $action = $env{'form.customroleaction'};
1.406.2.14 raeburn 5115: my ($rolename,$helpitem);
1.324 raeburn 5116: if ($action eq 'new') {
5117: $rolename=$env{'form.newrolename'};
5118: } else {
5119: $rolename=$env{'form.rolename'};
1.59 www 5120: }
5121:
1.324 raeburn 5122: my ($crstype,$context);
5123: if ($env{'request.course.id'}) {
5124: $crstype = &Apache::loncommon::course_type();
5125: $context = 'course';
1.406.2.14 raeburn 5126: $helpitem = 'Course_Editing_Custom_Roles';
1.324 raeburn 5127: } else {
5128: $context = 'domain';
1.406.2.5 raeburn 5129: $crstype = 'course';
1.406.2.14 raeburn 5130: $helpitem = 'Domain_Editing_Custom_Roles';
1.324 raeburn 5131: }
1.351 raeburn 5132:
5133: $rolename=~s/[^A-Za-z0-9]//gs;
5134: if (!$rolename || $env{'form.phase'} eq 'pickrole') {
1.406.2.14 raeburn 5135: &print_username_entry_form($r,$context,undef,undef,undef,$crstype,$brcrum,
5136: $permission);
1.351 raeburn 5137: return;
5138: }
5139:
1.406.2.5 raeburn 5140: my $formname = 'form1';
5141: my %privs=();
5142: my $body_top = '<h2>';
5143: # ------------------------------------------------------- Does this role exist?
1.59 www 5144: my ($rdummy,$roledef)=
5145: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5146: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.406.2.5 raeburn 5147: $body_top .= &mt('Existing Role').' "';
1.61 www 5148: # ------------------------------------------------- Get current role privileges
1.406.2.5 raeburn 5149: ($privs{'system'},$privs{'domain'},$privs{'course'})=split(/\_/,$roledef);
5150: if ($privs{'system'} =~ /bre\&S/) {
5151: if ($context eq 'domain') {
5152: $crstype = 'Course';
5153: } elsif ($crstype eq 'Community') {
5154: $privs{'system'} =~ s/bre\&S//;
5155: }
5156: } elsif ($context eq 'domain') {
5157: $crstype = 'Course';
1.324 raeburn 5158: }
1.59 www 5159: } else {
1.406.2.5 raeburn 5160: $body_top .= &mt('New Role').' "';
5161: $roledef='';
1.59 www 5162: }
1.153 banghart 5163: $body_top .= $rolename.'"</h2>';
1.406.2.5 raeburn 5164:
5165: # ------------------------------------------------------- What can be assigned?
5166: my %full=();
5167: my %levels=(
5168: course => {},
5169: domain => {},
5170: system => {},
5171: );
5172: my %levelscurrent=(
5173: course => {},
5174: domain => {},
5175: system => {},
5176: );
5177: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
1.160 raeburn 5178: my ($jsback,$elements) = &crumb_utilities();
1.406.2.5 raeburn 5179: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5180: my $head_script =
5181: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,
5182: \%full,\@templateroles,$jsback);
1.351 raeburn 5183: push (@{$brcrum},
1.406.2.5 raeburn 5184: {href => "javascript:backPage(document.$formname,'pickrole','')",
1.351 raeburn 5185: text => "Pick custom role",
5186: faq => 282,bug=>'Instructor Interface',},
1.406.2.5 raeburn 5187: {href => "javascript:backPage(document.$formname,'','')",
1.351 raeburn 5188: text => "Edit custom role",
5189: faq => 282,
5190: bug => 'Instructor Interface',
1.406.2.14 raeburn 5191: help => $helpitem}
1.351 raeburn 5192: );
5193: my $args = { bread_crumbs => $brcrum,
5194: bread_crumbs_component => 'User Management'};
5195: $r->print(&Apache::loncommon::start_page('Custom Role Editor',
5196: $head_script,$args).
5197: $body_top);
1.406.2.5 raeburn 5198: $r->print('<form name="'.$formname.'" method="post" action="">'."\n".
5199: &Apache::lonuserutils::custom_role_header($context,$crstype,
5200: \@templateroles,$prefix));
1.264 bisitz 5201:
1.61 www 5202: $r->print(<<ENDCCF);
5203: <input type="hidden" name="phase" value="set_custom_roles" />
5204: <input type="hidden" name="rolename" value="$rolename" />
5205: ENDCCF
1.406.2.5 raeburn 5206: $r->print(&Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
5207: \%levelscurrent,$prefix));
1.135 raeburn 5208: $r->print(&Apache::loncommon::end_data_table().
1.190 raeburn 5209: '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
1.160 raeburn 5210: '<input type="hidden" name="startrolename" value="'.$env{'form.rolename'}.
1.406.2.5 raeburn 5211: '" />'."\n".'<input type="hidden" name="currstate" value="" />'."\n".
1.160 raeburn 5212: '<input type="reset" value="'.&mt("Reset").'" />'."\n".
1.351 raeburn 5213: '<input type="submit" value="'.&mt('Save').'" /></form>');
1.61 www 5214: }
1.406.2.5 raeburn 5215:
1.61 www 5216: # ---------------------------------------------------------- Call to definerole
5217: sub set_custom_role {
1.406.2.14 raeburn 5218: my ($r,$context,$brcrum,$prefix,$permission) = @_;
1.101 albertel 5219: my $rolename=$env{'form.rolename'};
1.63 www 5220: $rolename=~s/[^A-Za-z0-9]//gs;
1.150 banghart 5221: if (!$rolename) {
1.406.2.14 raeburn 5222: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.61 www 5223: return;
5224: }
1.160 raeburn 5225: my ($jsback,$elements) = &crumb_utilities();
1.301 bisitz 5226: my $jscript = '<script type="text/javascript">'
5227: .'// <![CDATA['."\n"
5228: .$jsback."\n"
5229: .'// ]]>'."\n"
5230: .'</script>'."\n";
1.406.2.14 raeburn 5231: my $helpitem = 'Course_Editing_Custom_Roles';
5232: if ($context eq 'domain') {
5233: $helpitem = 'Domain_Editing_Custom_Roles';
5234: }
1.352 raeburn 5235: push(@{$brcrum},
5236: {href => "javascript:backPage(document.customresult,'pickrole','')",
5237: text => "Pick custom role",
5238: faq => 282,
5239: bug => 'Instructor Interface',},
5240: {href => "javascript:backPage(document.customresult,'selected_custom_edit','')",
5241: text => "Edit custom role",
5242: faq => 282,
5243: bug => 'Instructor Interface',},
5244: {href => "javascript:backPage(document.customresult,'set_custom_roles','')",
5245: text => "Result",
5246: faq => 282,
5247: bug => 'Instructor Interface',
1.406.2.14 raeburn 5248: help => $helpitem,}
1.352 raeburn 5249: );
5250: my $args = { bread_crumbs => $brcrum,
1.406.2.5 raeburn 5251: bread_crumbs_component => 'User Management'};
1.351 raeburn 5252: $r->print(&Apache::loncommon::start_page('Save Custom Role',$jscript,$args));
1.160 raeburn 5253:
1.393 raeburn 5254: my $newrole;
1.61 www 5255: my ($rdummy,$roledef)=
1.110 albertel 5256: &Apache::lonnet::get('roles',["rolesdef_$rolename"]);
5257:
1.61 www 5258: # ------------------------------------------------------- Does this role exist?
1.188 raeburn 5259: $r->print('<h3>');
1.61 www 5260: if (($rdummy ne 'con_lost') && ($roledef ne '')) {
1.73 sakharuk 5261: $r->print(&mt('Existing Role').' "');
1.61 www 5262: } else {
1.73 sakharuk 5263: $r->print(&mt('New Role').' "');
1.61 www 5264: $roledef='';
1.393 raeburn 5265: $newrole = 1;
1.61 www 5266: }
1.188 raeburn 5267: $r->print($rolename.'"</h3>');
1.406.2.5 raeburn 5268: # ------------------------------------------------- Assign role and show result
1.61 www 5269:
1.387 bisitz 5270: my $errmsg;
1.406.2.5 raeburn 5271: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$prefix);
5272: # Assign role and return result
5273: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
5274: $newprivs{'c'});
1.387 bisitz 5275: if ($result ne 'ok') {
5276: $errmsg = ': '.$result;
5277: }
5278: my $message =
5279: &Apache::lonhtmlcommon::confirm_success(
5280: &mt('Defining Role').$errmsg, ($result eq 'ok' ? 0 : 1));
1.101 albertel 5281: if ($env{'request.course.id'}) {
5282: my $url='/'.$env{'request.course.id'};
1.63 www 5283: $url=~s/\_/\//g;
1.387 bisitz 5284: $result =
5285: &Apache::lonnet::assigncustomrole(
5286: $env{'user.domain'},$env{'user.name'},
5287: $url,
5288: $env{'user.domain'},$env{'user.name'},
5289: $rolename,undef,undef,undef,$context);
5290: if ($result ne 'ok') {
5291: $errmsg = ': '.$result;
5292: }
5293: $message .=
5294: '<br />'
5295: .&Apache::lonhtmlcommon::confirm_success(
5296: &mt('Assigning Role to Self').$errmsg, ($result eq 'ok' ? 0 : 1));
1.63 www 5297: }
1.380 bisitz 5298: $r->print(
1.387 bisitz 5299: &Apache::loncommon::confirmwrapper($message)
5300: .'<br />'
5301: .&Apache::lonhtmlcommon::actionbox([
5302: '<a href="javascript:backPage(document.customresult,'."'pickrole'".')">'
5303: .&mt('Create or edit another custom role')
5304: .'</a>'])
1.380 bisitz 5305: .'<form name="customresult" method="post" action="">'
1.387 bisitz 5306: .&Apache::lonhtmlcommon::echo_form_input([])
5307: .'</form>'
1.380 bisitz 5308: );
1.58 www 5309: }
5310:
1.406.2.20.2. (raeburn 5311:): sub display_coauthor_managers {
5312:): my ($permission) = @_;
5313:): my $output;
5314:): if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5315:): $output = '<form action="/adm/createuser" method="post" name="camanagers">'.
5316:): '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n".
5317:): '<p>';
5318:): my (@possmanagers,@custommanagers);
5319:): my %userenv =
5320:): &Apache::lonnet::userenvironment($env{'user.domain'},
5321:): $env{'user.name'},
5322:): 'authormanagers');
5323:): my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5324:): ['active','future'],['ca']);
5325:): if (keys(%ca_roles)) {
5326:): foreach my $entry (sort(keys(%ca_roles))) {
5327:): if ($entry =~ /^($match_username\:$match_domain):ca$/) {
5328:): my $user = $1;
5329:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5330:): push(@possmanagers,$user);
5331:): }
5332:): }
5333:): }
5334:): }
5335:): if ($userenv{'authormanagers'} eq '') {
5336:): $output .= &mt('Currently author manages co-author roles');
5337:): } else {
5338:): if (keys(%ca_roles)) {
5339:): foreach my $user (split(/,/,$userenv{'authormanagers'})) {
5340:): if ($user =~ /^($match_username)\:($match_domain)$/) {
5341:): if (exists($ca_roles{$user.':ca'})) {
5342:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5343:): push(@custommanagers,$user);
5344:): }
5345:): }
5346:): }
5347:): }
5348:): }
5349:): if (@custommanagers) {
5350:): $output .= &mt('Co-authors with active or future roles who currently manage co-author roles: [_1]',
5351:): '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @custommanagers));
5352:): } else {
5353:): $output .= &mt('Currently author manages co-author roles');
5354:): }
5355:): }
5356:): $output .= "</p>\n";
5357:): if (@possmanagers) {
5358:): $output .= '<p>'.&mt('If checked, can manage').': ';
5359:): foreach my $user (@possmanagers) {
5360:): my $checked;
5361:): if (grep(/^\Q$user\E$/,@custommanagers)) {
5362:): $checked = ' checked="checked"';
5363:): }
5364:): $output .= '<span style="LC_nobreak"><label>'.
5365:): '<input type="checkbox" name="custommanagers" '.
5366:): 'value="'.&HTML::Entities::encode($user,'\'<>"&').'"'.$checked.' />'.
5367:): &Apache::loncommon::plainname(split(/:/,$user))." ($user)".'</label></span> '."\n";
5368:): }
5369:): $output .= '<input type="hidden" name="state" value="process" /></p>'."\n".
5370:): '<p><input type="submit" value="'.&mt('Save changes').'" /></p>'."\n";
5371:): } else {
5372:): $output .= '<p>'.&mt('No co-author roles assignable as manager').'</p>';
5373:): }
5374:): $output .= '</form>';
5375:): } else {
5376:): $output = '<span class="LC_warning">'.
5377:): &mt('You do not have permission to perform this action').
5378:): '</span>';
5379:): }
5380:): return $output;
5381:): }
5382:):
5383:): sub update_coauthor_managers {
5384:): my ($permission) = @_;
5385:): my $output;
5386:): if ((ref($permission) eq 'HASH') && ($permission->{'author'})) {
5387:): my ($current,$newval,@possibles,@managers);
5388:): my %userenv =
5389:): &Apache::lonnet::userenvironment($env{'user.domain'},
5390:): $env{'user.name'},
5391:): 'authormanagers');
5392:): $current = $userenv{'authormanagers'};
5393:): @possibles = &Apache::loncommon::get_env_multiple('form.custommanagers');
5394:): if (@possibles) {
5395:): my %ca_roles = &Apache::lonnet::get_my_roles(undef,undef,undef,
5396:): ['active','future'],['ca']);
5397:): if (keys(%ca_roles)) {
5398:): foreach my $user (@possibles) {
5399:): if ($user =~ /^($match_username):($match_domain)$/) {
5400:): if (exists($ca_roles{$user.':ca'})) {
5401:): unless ($user eq $env{'user.name'}.':'.$env{'user.domain'}) {
5402:): push(@managers,$user);
5403:): }
5404:): }
5405:): }
5406:): }
5407:): if (@managers) {
5408:): $newval = join(',',sort(@managers));
5409:): }
5410:): }
5411:): }
5412:): if ($current eq $newval) {
5413:): $output = &mt('No changes made to management of co-author roles');
5414:): } else {
5415:): my $chgresult =
5416:): &Apache::lonnet::put('environment',{'authormanagers' => $newval},
5417:): $env{'user.domain'},$env{'user.name'});
5418:): if ($chgresult eq 'ok') {
5419:): &Apache::lonnet::appenv({'environment.authormanagers' => $newval});
5420:): my (@adds,@dels);
5421:): if ($newval eq '') {
5422:): @dels = split(/,/,$current);
5423:): } elsif ($current eq '') {
5424:): @adds = @managers;
5425:): } else {
5426:): my @old = split(/,/,$current);
5427:): my @diffs = &Apache::loncommon::compare_arrays(\@old,\@managers);
5428:): if (@diffs) {
5429:): foreach my $user (@diffs) {
5430:): if (grep(/^\Q$user\E$/,@old)) {
5431:): push(@dels,$user);
5432:): } elsif (grep(/^\Q$user\E$/,@managers)) {
5433:): push(@adds,$user);
5434:): }
5435:): }
5436:): }
5437:): }
5438:): my $key = "internal.manager./$env{'user.domain'}/$env{'user.name'}";
5439:): if (@dels) {
5440:): foreach my $user (@dels) {
5441:): if ($user =~ /^($match_username):($match_domain)$/) {
5442:): &Apache::lonnet::del('environment',[$key],$2,$1);
5443:): }
5444:): }
5445:): }
5446:): if (@adds) {
5447:): foreach my $user (@adds) {
5448:): if ($user =~ /^($match_username):($match_domain)$/) {
5449:): &Apache::lonnet::put('environment',{$key => 1},$2,$1);
5450:): }
5451:): }
5452:): }
5453:): if ($newval eq '') {
5454:): $output = &mt('Management of co-authors set to be author-only');
5455:): } else {
5456:): $output .= &mt('Co-authors who can manage co-author roles set to: [_1]',
5457:): '<br />'.join(', ',map { &Apache::loncommon::plainname(split(':',$_))." ($_)"; } @managers));
5458:): }
5459:): }
5460:): }
5461:): } else {
5462:): $output = '<span class="LC_warning">'.
5463:): &mt('You do not have permission to perform this action').
5464:): '</span>';
5465:): }
5466:): return $output;
5467:): }
5468:):
1.2 www 5469: # ================================================================ Main Handler
5470: sub handler {
5471: my $r = shift;
5472: if ($r->header_only) {
1.68 www 5473: &Apache::loncommon::content_type($r,'text/html');
1.2 www 5474: $r->send_http_header;
5475: return OK;
5476: }
1.406.2.14 raeburn 5477: my ($context,$crstype,$cid,$cnum,$cdom,$allhelpitems);
5478:
1.190 raeburn 5479: if ($env{'request.course.id'}) {
5480: $context = 'course';
1.318 raeburn 5481: $crstype = &Apache::loncommon::course_type();
1.190 raeburn 5482: } elsif ($env{'request.role'} =~ /^au\./) {
1.206 raeburn 5483: $context = 'author';
1.406.2.20.2. (raeburn 5484:): } elsif ($env{'request.role'} =~ m{^(ca|aa)\./$match_domain/$match_username$}) {
5485:): $context = 'coauthor';
1.190 raeburn 5486: } else {
5487: $context = 'domain';
5488: }
1.375 raeburn 5489:
1.406.2.14 raeburn 5490: my ($permission,$allowed) =
5491: &Apache::lonuserutils::get_permission($context,$crstype);
1.406.2.20.2. (raeburn 5492:): if (($context eq 'coauthor') && ($allowed)) {
5493:): $context = 'author';
5494:): }
1.406.2.14 raeburn 5495:
5496: if ($allowed) {
5497: my @allhelp;
5498: if ($context eq 'course') {
5499: $cid = $env{'request.course.id'};
5500: $cdom = $env{'course.'.$cid.'.domain'};
5501: $cnum = $env{'course.'.$cid.'.num'};
5502:
5503: if ($permission->{'cusr'}) {
5504: push(@allhelp,'Course_Create_Class_List');
5505: }
5506: if ($permission->{'view'} || $permission->{'cusr'}) {
5507: push(@allhelp,('Course_Change_Privileges','Course_View_Class_List'));
5508: }
5509: if ($permission->{'custom'}) {
5510: push(@allhelp,'Course_Editing_Custom_Roles');
5511: }
5512: if ($permission->{'cusr'}) {
5513: push(@allhelp,('Course_Add_Student','Course_Drop_Student'));
5514: }
5515: unless ($permission->{'cusr_section'}) {
5516: if (&Apache::lonnet::auto_run($cnum,$cdom) && (($permission->{'cusr'}) || ($permission->{'view'}))) {
5517: push(@allhelp,'Course_Automated_Enrollment');
5518: }
1.406.2.20.2. (raeburn 5519:): if (($permission->{'selfenrolladmin'}) || ($permission->{'selfenrollview'})) {
1.406.2.14 raeburn 5520: push(@allhelp,'Course_Approve_Selfenroll');
5521: }
5522: }
5523: if ($permission->{'grp_manage'}) {
5524: push(@allhelp,'Course_Manage_Group');
5525: }
5526: if ($permission->{'view'} || $permission->{'cusr'}) {
5527: push(@allhelp,'Course_User_Logs');
5528: }
5529: } elsif ($context eq 'author') {
5530: push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5531: 'Author_View_Coauthor_List','Author_User_Logs'));
1.406.2.20.2. (raeburn 5532:): } elsif ($context eq 'coauthor') {
5533:): if ($permission->{'cusr'}) {
5534:): push(@allhelp,('Author_Change_Privileges','Author_Create_Coauthor_List',
5535:): 'Author_View_Coauthor_List','Author_User_Logs'));
5536:): } elsif ($permission->{'view'}) {
5537:): push(@allhelp,'Author_View_Coauthor_List');
5538:): }
1.406.2.14 raeburn 5539: } else {
5540: if ($permission->{'cusr'}) {
5541: push(@allhelp,'Domain_Change_Privileges');
5542: if ($permission->{'activity'}) {
5543: push(@allhelp,'Domain_User_Access_Logs');
5544: }
5545: push(@allhelp,('Domain_Create_Users','Domain_View_Users_List'));
5546: if ($permission->{'custom'}) {
5547: push(@allhelp,'Domain_Editing_Custom_Roles');
5548: }
5549: push(@allhelp,('Domain_Role_Approvals','Domain_Username_Approvals','Domain_Change_Logs'));
5550: } elsif ($permission->{'view'}) {
5551: push(@allhelp,'Domain_View_Privileges');
5552: if ($permission->{'activity'}) {
5553: push(@allhelp,'Domain_User_Access_Logs');
5554: }
5555: push(@allhelp,('Domain_View_Users_List','Domain_Change_Logs'));
5556: }
5557: }
5558: if (@allhelp) {
5559: $allhelpitems = join(',',@allhelp);
5560: }
5561: }
5562:
1.190 raeburn 5563: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.233 raeburn 5564: ['action','state','callingform','roletype','showrole','bulkaction','popup','phase',
1.406.2.20.2. (raeburn 5565:): 'username','domain','srchterm','srchdomain','srchin','srchby','srchtype','queue',
5566:): 'forceedit']);
1.190 raeburn 5567: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.351 raeburn 5568: my $args;
5569: my $brcrum = [];
5570: my $bread_crumbs_component = 'User Management';
1.391 raeburn 5571: if (($env{'form.action'} ne 'dateselect') && ($env{'form.action'} ne 'displayuserreq')) {
1.351 raeburn 5572: $brcrum = [{href=>"/adm/createuser",
5573: text=>"User Management",
1.406.2.14 raeburn 5574: help=>$allhelpitems}
1.351 raeburn 5575: ];
1.202 raeburn 5576: }
1.190 raeburn 5577: if (!$allowed) {
1.358 raeburn 5578: if ($context eq 'course') {
5579: $r->internal_redirect('/adm/viewclasslist');
5580: return OK;
1.406.2.20.2. (raeburn 5581:): } elsif ($context eq 'coauthor') {
5582:): $r->internal_redirect('/adm/viewcoauthors');
5583:): return OK;
1.358 raeburn 5584: }
1.190 raeburn 5585: $env{'user.error.msg'}=
5586: "/adm/createuser:cst:0:0:Cannot create/modify user data ".
5587: "or view user status.";
5588: return HTTP_NOT_ACCEPTABLE;
5589: }
5590:
5591: &Apache::loncommon::content_type($r,'text/html');
5592: $r->send_http_header;
5593:
1.375 raeburn 5594: my $showcredits;
5595: if ((($context eq 'course') && ($crstype eq 'Course')) ||
5596: ($context eq 'domain')) {
5597: my %domdefaults =
5598: &Apache::lonnet::get_domain_defaults($env{'request.role.domain'});
5599: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
5600: $showcredits = 1;
5601: }
5602: }
5603:
1.190 raeburn 5604: # Main switch on form.action and form.state, as appropriate
5605: if (! exists($env{'form.action'})) {
1.351 raeburn 5606: $args = {bread_crumbs => $brcrum,
5607: bread_crumbs_component => $bread_crumbs_component};
5608: $r->print(&header(undef,$args));
1.318 raeburn 5609: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 5610: } elsif ($env{'form.action'} eq 'upload' && $permission->{'cusr'}) {
1.406.2.14 raeburn 5611: my $helpitem = 'Course_Create_Class_List';
5612: if ($context eq 'author') {
5613: $helpitem = 'Author_Create_Coauthor_List';
5614: } elsif ($context eq 'domain') {
5615: $helpitem = 'Domain_Create_Users';
5616: }
1.351 raeburn 5617: push(@{$brcrum},
5618: { href => '/adm/createuser?action=upload&state=',
5619: text => 'Upload Users List',
1.406.2.14 raeburn 5620: help => $helpitem,
1.351 raeburn 5621: });
5622: $bread_crumbs_component = 'Upload Users List';
5623: $args = {bread_crumbs => $brcrum,
5624: bread_crumbs_component => $bread_crumbs_component};
5625: $r->print(&header(undef,$args));
1.190 raeburn 5626: $r->print('<form name="studentform" method="post" '.
5627: 'enctype="multipart/form-data" '.
5628: ' action="/adm/createuser">'."\n");
5629: if (! exists($env{'form.state'})) {
5630: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5631: } elsif ($env{'form.state'} eq 'got_file') {
1.406.2.15 raeburn 5632: my $result =
5633: &Apache::lonuserutils::print_upload_manager_form($r,$context,
5634: $permission,
5635: $crstype,$showcredits);
5636: if ($result eq 'missingdata') {
5637: delete($env{'form.state'});
5638: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5639: }
1.190 raeburn 5640: } elsif ($env{'form.state'} eq 'enrolling') {
5641: if ($env{'form.datatoken'}) {
1.406.2.15 raeburn 5642: my $result = &Apache::lonuserutils::upfile_drop_add($r,$context,
5643: $permission,
5644: $showcredits);
5645: if ($result eq 'missingdata') {
5646: delete($env{'form.state'});
5647: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5648: } elsif ($result eq 'invalidhome') {
5649: $env{'form.state'} = 'got_file';
5650: delete($env{'form.lcserver'});
5651: my $result =
5652: &Apache::lonuserutils::print_upload_manager_form($r,$context,$permission,
5653: $crstype,$showcredits);
5654: if ($result eq 'missingdata') {
5655: delete($env{'form.state'});
5656: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5657: }
5658: }
5659: } else {
5660: delete($env{'form.state'});
5661: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
1.190 raeburn 5662: }
5663: } else {
5664: &Apache::lonuserutils::print_first_users_upload_form($r,$context);
5665: }
1.406.2.15 raeburn 5666: $r->print('</form>');
1.406.2.5 raeburn 5667: } elsif (((($env{'form.action'} eq 'singleuser') || ($env{'form.action'}
5668: eq 'singlestudent')) && ($permission->{'cusr'})) ||
1.406.2.6 raeburn 5669: (($env{'form.action'} eq 'singleuser') && ($permission->{'view'})) ||
1.406.2.5 raeburn 5670: (($env{'form.action'} eq 'accesslogs') && ($permission->{'activity'}))) {
1.190 raeburn 5671: my $phase = $env{'form.phase'};
5672: my @search = ('srchterm','srchby','srchin','srchtype','srchdomain');
1.192 albertel 5673: &Apache::loncreateuser::restore_prev_selections();
5674: my $srch;
5675: foreach my $item (@search) {
5676: $srch->{$item} = $env{'form.'.$item};
5677: }
1.207 raeburn 5678: if (($phase eq 'get_user_info') || ($phase eq 'userpicked') ||
1.406.2.5 raeburn 5679: ($phase eq 'createnewuser') || ($phase eq 'activity')) {
1.207 raeburn 5680: if ($env{'form.phase'} eq 'createnewuser') {
5681: my $response;
5682: if ($env{'form.srchterm'} !~ /^$match_username$/) {
1.366 bisitz 5683: my $response =
5684: '<span class="LC_warning">'
5685: .&mt('You must specify a valid username. Only the following are allowed:'
5686: .' letters numbers - . @')
5687: .'</span>';
1.221 raeburn 5688: $env{'form.phase'} = '';
1.375 raeburn 5689: &print_username_entry_form($r,$context,$response,$srch,undef,
1.406.2.14 raeburn 5690: $crstype,$brcrum,$permission);
1.207 raeburn 5691: } else {
5692: my $ccuname =&LONCAPA::clean_username($srch->{'srchterm'});
5693: my $ccdomain=&LONCAPA::clean_domain($srch->{'srchdomain'});
5694: &print_user_modification_page($r,$ccuname,$ccdomain,
1.221 raeburn 5695: $srch,$response,$context,
1.375 raeburn 5696: $permission,$crstype,$brcrum,
5697: $showcredits);
1.207 raeburn 5698: }
5699: } elsif ($env{'form.phase'} eq 'get_user_info') {
1.190 raeburn 5700: my ($currstate,$response,$forcenewuser,$results) =
1.221 raeburn 5701: &user_search_result($context,$srch);
1.190 raeburn 5702: if ($env{'form.currstate'} eq 'modify') {
5703: $currstate = $env{'form.currstate'};
5704: }
5705: if ($currstate eq 'select') {
5706: &print_user_selection_page($r,$response,$srch,$results,
1.351 raeburn 5707: \@search,$context,undef,$crstype,
5708: $brcrum);
1.406.2.5 raeburn 5709: } elsif (($currstate eq 'modify') || ($env{'form.action'} eq 'accesslogs')) {
5710: my ($ccuname,$ccdomain,$uhome);
1.190 raeburn 5711: if (($srch->{'srchby'} eq 'uname') &&
5712: ($srch->{'srchtype'} eq 'exact')) {
5713: $ccuname = $srch->{'srchterm'};
5714: $ccdomain= $srch->{'srchdomain'};
5715: } else {
5716: my @matchedunames = keys(%{$results});
5717: ($ccuname,$ccdomain) = split(/:/,$matchedunames[0]);
5718: }
5719: $ccuname =&LONCAPA::clean_username($ccuname);
5720: $ccdomain=&LONCAPA::clean_domain($ccdomain);
1.406.2.5 raeburn 5721: if ($env{'form.action'} eq 'accesslogs') {
5722: my $uhome;
5723: if (($ccuname ne '') && ($ccdomain ne '')) {
5724: $uhome = &Apache::lonnet::homeserver($ccuname,$ccdomain);
5725: }
5726: if (($uhome eq '') || ($uhome eq 'no_host')) {
5727: $env{'form.phase'} = '';
5728: undef($forcenewuser);
5729: #if ($response) {
5730: # unless ($response =~ m{\Q<br /><br />\E$}) {
5731: # $response .= '<br /><br />';
5732: # }
5733: #}
5734: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 5735: $forcenewuser,$crstype,$brcrum,
5736: $permission);
1.406.2.5 raeburn 5737: } else {
5738: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5739: }
5740: } else {
5741: if ($env{'form.forcenewuser'}) {
5742: $response = '';
5743: }
5744: &print_user_modification_page($r,$ccuname,$ccdomain,
5745: $srch,$response,$context,
5746: $permission,$crstype,$brcrum);
1.190 raeburn 5747: }
5748: } elsif ($currstate eq 'query') {
1.351 raeburn 5749: &print_user_query_page($r,'createuser',$brcrum);
1.190 raeburn 5750: } else {
1.229 raeburn 5751: $env{'form.phase'} = '';
1.207 raeburn 5752: &print_username_entry_form($r,$context,$response,$srch,
1.406.2.14 raeburn 5753: $forcenewuser,$crstype,$brcrum,
5754: $permission);
1.190 raeburn 5755: }
5756: } elsif ($env{'form.phase'} eq 'userpicked') {
5757: my $ccuname = &LONCAPA::clean_username($env{'form.seluname'});
5758: my $ccdomain = &LONCAPA::clean_domain($env{'form.seludom'});
1.406.2.5 raeburn 5759: if ($env{'form.action'} eq 'accesslogs') {
5760: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
5761: } else {
5762: &print_user_modification_page($r,$ccuname,$ccdomain,$srch,'',
5763: $context,$permission,$crstype,
5764: $brcrum);
5765: }
5766: } elsif ($env{'form.action'} eq 'accesslogs') {
5767: my $ccuname = &LONCAPA::clean_username($env{'form.accessuname'});
5768: my $ccdomain = &LONCAPA::clean_domain($env{'form.accessudom'});
5769: &print_useraccesslogs_display($r,$ccuname,$ccdomain,$permission,$brcrum);
1.190 raeburn 5770: }
5771: } elsif ($env{'form.phase'} eq 'update_user_data') {
1.406.2.17 raeburn 5772: &update_user_data($r,$context,$crstype,$brcrum,$showcredits,$permission);
1.190 raeburn 5773: } else {
1.351 raeburn 5774: &print_username_entry_form($r,$context,undef,$srch,undef,$crstype,
1.406.2.14 raeburn 5775: $brcrum,$permission);
1.190 raeburn 5776: }
5777: } elsif ($env{'form.action'} eq 'custom' && $permission->{'custom'}) {
1.406.2.5 raeburn 5778: my $prefix;
1.190 raeburn 5779: if ($env{'form.phase'} eq 'set_custom_roles') {
1.406.2.14 raeburn 5780: &set_custom_role($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5781: } else {
1.406.2.14 raeburn 5782: &custom_role_editor($r,$context,$brcrum,$prefix,$permission);
1.190 raeburn 5783: }
1.362 raeburn 5784: } elsif (($env{'form.action'} eq 'processauthorreq') &&
5785: ($permission->{'cusr'}) &&
5786: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5787: push(@{$brcrum},
5788: {href => '/adm/createuser?action=processauthorreq',
1.385 bisitz 5789: text => 'Authoring Space requests',
1.362 raeburn 5790: help => 'Domain_Role_Approvals'});
5791: $bread_crumbs_component = 'Authoring requests';
5792: if ($env{'form.state'} eq 'done') {
5793: push(@{$brcrum},
5794: {href => '/adm/createuser?action=authorreqqueue',
5795: text => 'Result',
5796: help => 'Domain_Role_Approvals'});
5797: $bread_crumbs_component = 'Authoring request result';
5798: }
5799: $args = { bread_crumbs => $brcrum,
5800: bread_crumbs_component => $bread_crumbs_component};
1.391 raeburn 5801: my $js = &usernamerequest_javascript();
5802: $r->print(&header(&add_script($js),$args));
1.362 raeburn 5803: if (!exists($env{'form.state'})) {
5804: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestauthor',
5805: $env{'request.role.domain'}));
5806: } elsif ($env{'form.state'} eq 'done') {
5807: $r->print('<h3>'.&mt('Authoring request processing').'</h3>'."\n");
5808: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestauthor',
5809: $env{'request.role.domain'}));
5810: }
1.391 raeburn 5811: } elsif (($env{'form.action'} eq 'processusernamereq') &&
5812: ($permission->{'cusr'}) &&
5813: (&Apache::lonnet::allowed('cau',$env{'request.role.domain'}))) {
5814: push(@{$brcrum},
5815: {href => '/adm/createuser?action=processusernamereq',
5816: text => 'LON-CAPA account requests',
5817: help => 'Domain_Username_Approvals'});
5818: $bread_crumbs_component = 'Account requests';
5819: if ($env{'form.state'} eq 'done') {
5820: push(@{$brcrum},
5821: {href => '/adm/createuser?action=usernamereqqueue',
5822: text => 'Result',
5823: help => 'Domain_Username_Approvals'});
5824: $bread_crumbs_component = 'LON-CAPA account request result';
5825: }
5826: $args = { bread_crumbs => $brcrum,
5827: bread_crumbs_component => $bread_crumbs_component};
5828: my $js = &usernamerequest_javascript();
5829: $r->print(&header(&add_script($js),$args));
5830: if (!exists($env{'form.state'})) {
5831: $r->print(&Apache::loncoursequeueadmin::display_queued_requests('requestusername',
5832: $env{'request.role.domain'}));
5833: } elsif ($env{'form.state'} eq 'done') {
5834: $r->print('<h3>'.&mt('LON-CAPA account request processing').'</h3>'."\n");
5835: $r->print(&Apache::loncoursequeueadmin::update_request_queue('requestusername',
5836: $env{'request.role.domain'}));
5837: }
5838: } elsif (($env{'form.action'} eq 'displayuserreq') &&
5839: ($permission->{'cusr'})) {
5840: my $dom = $env{'form.domain'};
5841: my $uname = $env{'form.username'};
5842: my $warning;
5843: if (($dom =~ /^$match_domain$/) && (&Apache::lonnet::domain($dom) ne '')) {
5844: if (($dom eq $env{'request.role.domain'}) && (&Apache::lonnet::allowed('ccc',$dom))) {
5845: if (($uname =~ /^$match_username$/) && ($env{'form.queue'} eq 'approval')) {
5846: my $uhome = &Apache::lonnet::homeserver($uname,$dom);
5847: if ($uhome eq 'no_host') {
5848: my $queue = $env{'form.queue'};
5849: my $reqkey = &escape($uname).'_'.$queue;
5850: my $namespace = 'usernamequeue';
5851: my $domconfig = &Apache::lonnet::get_domainconfiguser($dom);
5852: my %queued =
5853: &Apache::lonnet::get($namespace,[$reqkey],$dom,$domconfig);
5854: unless ($queued{$reqkey}) {
5855: $warning = &mt('No information was found for this LON-CAPA account request.');
5856: }
5857: } else {
5858: $warning = &mt('A LON-CAPA account already exists for the requested username and domain.');
5859: }
5860: } else {
5861: $warning = &mt('LON-CAPA account request status check is for an invalid username.');
5862: }
5863: } else {
5864: $warning = &mt('You do not have rights to view LON-CAPA account requests in the domain specified.');
5865: }
5866: } else {
5867: $warning = &mt('LON-CAPA account request status check is for an invalid domain.');
5868: }
5869: my $args = { only_body => 1 };
5870: $r->print(&header(undef,$args).
5871: '<h3>'.&mt('LON-CAPA Account Request Details').'</h3>');
5872: if ($warning ne '') {
5873: $r->print('<div class="LC_warning">'.$warning.'</div>');
5874: } else {
5875: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
5876: my $domconfiguser = &Apache::lonnet::get_domainconfiguser($dom);
5877: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
5878: if (ref($domconfig{'usercreation'}) eq 'HASH') {
5879: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
5880: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}) eq 'HASH') {
5881: my %info =
5882: &Apache::lonnet::get('nohist_requestedusernames',[$uname],$dom,$domconfiguser);
5883: if (ref($info{$uname}) eq 'HASH') {
1.396 raeburn 5884: my $usertype = $info{$uname}{'inststatus'};
5885: unless ($usertype) {
5886: $usertype = 'default';
5887: }
1.406.2.16 raeburn 5888: my ($showstatus,$showemail,$pickstart);
5889: my $numextras = 0;
5890: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5891: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
5892: if (ref($usertypes) eq 'HASH') {
5893: if ($usertypes->{$usertype}) {
5894: $showstatus = $usertypes->{$usertype};
5895: } else {
5896: $showstatus = $othertitle;
5897: }
5898: if ($showstatus) {
5899: $numextras ++;
5900: }
5901: }
5902: }
5903: if (($info{$uname}{'email'} ne '') && ($info{$uname}{'email'} ne $uname)) {
5904: $showemail = $info{$uname}{'email'};
5905: $numextras ++;
5906: }
1.396 raeburn 5907: if (ref($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}) eq 'HASH') {
5908: if ((ref($infofields) eq 'ARRAY') && (ref($infotitles) eq 'HASH')) {
1.406.2.16 raeburn 5909: $pickstart = 1;
1.396 raeburn 5910: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
1.406.2.16 raeburn 5911: my ($num,$count);
1.396 raeburn 5912: $count = scalar(keys(%{$domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}}));
1.406.2.16 raeburn 5913: $count += $numextras;
1.396 raeburn 5914: foreach my $field (@{$infofields}) {
5915: next unless ($domconfig{'usercreation'}{'cancreate'}{'emailusername'}{$usertype}{$field});
5916: next unless ($infotitles->{$field});
5917: $r->print(&Apache::lonhtmlcommon::row_title($infotitles->{$field}).
5918: $info{$uname}{$field});
5919: $num ++;
1.406.2.16 raeburn 5920: unless ($count == $num) {
1.396 raeburn 5921: $r->print(&Apache::lonhtmlcommon::row_closure());
5922: }
5923: }
1.406.2.16 raeburn 5924: }
5925: }
5926: if ($numextras) {
5927: unless ($pickstart) {
5928: $r->print('<div>'.&Apache::lonhtmlcommon::start_pick_box());
5929: $pickstart = 1;
5930: }
5931: if ($showemail) {
5932: my $closure = '';
5933: unless ($showstatus) {
5934: $closure = 1;
1.391 raeburn 5935: }
1.406.2.16 raeburn 5936: $r->print(&Apache::lonhtmlcommon::row_title(&mt('E-mail address')).
5937: $showemail.
5938: &Apache::lonhtmlcommon::row_closure($closure));
5939: }
5940: if ($showstatus) {
5941: $r->print(&Apache::lonhtmlcommon::row_title(&mt('Status type[_1](self-reported)','<br />')).
5942: $showstatus.
5943: &Apache::lonhtmlcommon::row_closure(1));
1.391 raeburn 5944: }
5945: }
1.406.2.16 raeburn 5946: if ($pickstart) {
5947: $r->print(&Apache::lonhtmlcommon::end_pick_box().'</div>');
5948: } else {
5949: $r->print('<div>'.&mt('No information to display for this account request.').'</div>');
5950: }
5951: } else {
5952: $r->print('<div>'.&mt('No information available for this account request.').'</div>');
1.391 raeburn 5953: }
5954: }
5955: }
5956: }
5957: }
1.406.2.16 raeburn 5958: $r->print(&close_popup_form());
1.207 raeburn 5959: } elsif (($env{'form.action'} eq 'listusers') &&
5960: ($permission->{'view'} || $permission->{'cusr'})) {
1.406.2.14 raeburn 5961: my $helpitem = 'Course_View_Class_List';
5962: if ($context eq 'author') {
5963: $helpitem = 'Author_View_Coauthor_List';
5964: } elsif ($context eq 'domain') {
5965: $helpitem = 'Domain_View_Users_List';
5966: }
1.202 raeburn 5967: if ($env{'form.phase'} eq 'bulkchange') {
1.351 raeburn 5968: push(@{$brcrum},
5969: {href => '/adm/createuser?action=listusers',
5970: text => "List Users"},
5971: {href => "/adm/createuser",
5972: text => "Result",
1.406.2.14 raeburn 5973: help => $helpitem});
1.351 raeburn 5974: $bread_crumbs_component = 'Update Users';
5975: $args = {bread_crumbs => $brcrum,
5976: bread_crumbs_component => $bread_crumbs_component};
5977: $r->print(&header(undef,$args));
1.202 raeburn 5978: my $setting = $env{'form.roletype'};
5979: my $choice = $env{'form.bulkaction'};
5980: if ($permission->{'cusr'}) {
1.336 raeburn 5981: &Apache::lonuserutils::update_user_list($r,$context,$setting,$choice,$crstype);
1.221 raeburn 5982: } else {
5983: $r->print(&mt('You are not authorized to make bulk changes to user roles'));
1.223 raeburn 5984: $r->print('<p><a href="/adm/createuser?action=listusers">'.&mt('Display User Lists').'</a>');
1.202 raeburn 5985: }
5986: } else {
1.351 raeburn 5987: push(@{$brcrum},
5988: {href => '/adm/createuser?action=listusers',
5989: text => "List Users",
1.406.2.14 raeburn 5990: help => $helpitem});
1.351 raeburn 5991: $bread_crumbs_component = 'List Users';
5992: $args = {bread_crumbs => $brcrum,
5993: bread_crumbs_component => $bread_crumbs_component};
1.202 raeburn 5994: my ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles);
5995: my $formname = 'studentform';
1.364 raeburn 5996: my $hidecall = "hide_searching();";
1.321 raeburn 5997: if (($context eq 'domain') && (($env{'form.roletype'} eq 'course') ||
5998: ($env{'form.roletype'} eq 'community'))) {
5999: if ($env{'form.roletype'} eq 'course') {
6000: ($cb_jscript,$jscript,$totcodes,$codetitles,$idlist,$idlist_titles) =
6001: &Apache::lonuserutils::courses_selector($env{'request.role.domain'},
6002: $formname);
6003: } elsif ($env{'form.roletype'} eq 'community') {
6004: $cb_jscript =
6005: &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
6006: my %elements = (
6007: coursepick => 'radio',
6008: coursetotal => 'text',
6009: courselist => 'text',
6010: );
6011: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements);
6012: }
1.364 raeburn 6013: $jscript .= &verify_user_display($context)."\n".
6014: &Apache::loncommon::check_uncheck_jscript();
1.202 raeburn 6015: my $js = &add_script($jscript).$cb_jscript;
6016: my $loadcode =
6017: &Apache::lonuserutils::course_selector_loadcode($formname);
6018: if ($loadcode ne '') {
1.364 raeburn 6019: $args->{add_entries} = {onload => "$loadcode;$hidecall"};
6020: } else {
6021: $args->{add_entries} = {onload => $hidecall};
1.202 raeburn 6022: }
1.351 raeburn 6023: $r->print(&header($js,$args));
1.191 raeburn 6024: } else {
1.364 raeburn 6025: $args->{add_entries} = {onload => $hidecall};
6026: $jscript = &verify_user_display($context).
6027: &Apache::loncommon::check_uncheck_jscript();
6028: $r->print(&header(&add_script($jscript),$args));
1.191 raeburn 6029: }
1.202 raeburn 6030: &Apache::lonuserutils::print_userlist($r,undef,$permission,$context,
1.375 raeburn 6031: $formname,$totcodes,$codetitles,$idlist,$idlist_titles,
6032: $showcredits);
1.191 raeburn 6033: }
1.213 raeburn 6034: } elsif ($env{'form.action'} eq 'drop' && $permission->{'cusr'}) {
1.318 raeburn 6035: my $brtext;
6036: if ($crstype eq 'Community') {
6037: $brtext = 'Drop Members';
6038: } else {
6039: $brtext = 'Drop Students';
6040: }
1.351 raeburn 6041: push(@{$brcrum},
6042: {href => '/adm/createuser?action=drop',
6043: text => $brtext,
6044: help => 'Course_Drop_Student'});
6045: if ($env{'form.state'} eq 'done') {
6046: push(@{$brcrum},
6047: {href=>'/adm/createuser?action=drop',
6048: text=>"Result"});
6049: }
6050: $bread_crumbs_component = $brtext;
6051: $args = {bread_crumbs => $brcrum,
6052: bread_crumbs_component => $bread_crumbs_component};
6053: $r->print(&header(undef,$args));
1.213 raeburn 6054: if (!exists($env{'form.state'})) {
1.318 raeburn 6055: &Apache::lonuserutils::print_drop_menu($r,$context,$permission,$crstype);
1.213 raeburn 6056: } elsif ($env{'form.state'} eq 'done') {
6057: &Apache::lonuserutils::update_user_list($r,$context,undef,
6058: $env{'form.action'});
6059: }
1.202 raeburn 6060: } elsif ($env{'form.action'} eq 'dateselect') {
6061: if ($permission->{'cusr'}) {
1.351 raeburn 6062: $r->print(&header(undef,{'no_nav_bar' => 1}).
1.375 raeburn 6063: &Apache::lonuserutils::date_section_selector($context,$permission,
6064: $crstype,$showcredits));
1.202 raeburn 6065: } else {
1.351 raeburn 6066: $r->print(&header(undef,{'no_nav_bar' => 1}).
6067: '<span class="LC_error">'.&mt('You do not have permission to modify dates or sections for users').'</span>');
1.202 raeburn 6068: }
1.237 raeburn 6069: } elsif ($env{'form.action'} eq 'selfenroll') {
1.406.2.20.2. (raeburn 6070:): my %currsettings;
6071:): if ($permission->{selfenrolladmin} || $permission->{selfenrollview}) {
6072:): %currsettings = (
1.398 raeburn 6073: selfenroll_types => $env{'course.'.$cid.'.internal.selfenroll_types'},
6074: selfenroll_registered => $env{'course.'.$cid.'.internal.selfenroll_registered'},
6075: selfenroll_section => $env{'course.'.$cid.'.internal.selfenroll_section'},
6076: selfenroll_notifylist => $env{'course.'.$cid.'.internal.selfenroll_notifylist'},
6077: selfenroll_approval => $env{'course.'.$cid.'.internal.selfenroll_approval'},
6078: selfenroll_limit => $env{'course.'.$cid.'.internal.selfenroll_limit'},
6079: selfenroll_cap => $env{'course.'.$cid.'.internal.selfenroll_cap'},
6080: selfenroll_start_date => $env{'course.'.$cid.'.internal.selfenroll_start_date'},
6081: selfenroll_end_date => $env{'course.'.$cid.'.internal.selfenroll_end_date'},
6082: selfenroll_start_access => $env{'course.'.$cid.'.internal.selfenroll_start_access'},
6083: selfenroll_end_access => $env{'course.'.$cid.'.internal.selfenroll_end_access'},
6084: default_enrollment_start_date => $env{'course.'.$cid.'.default_enrollment_start_date'},
6085: default_enrollment_end_date => $env{'course.'.$cid.'.default_enrollment_end_date'},
1.400 raeburn 6086: uniquecode => $env{'course.'.$cid.'.internal.uniquecode'},
1.398 raeburn 6087: );
1.406.2.20.2. (raeburn 6088:): }
6089:): if ($permission->{selfenrolladmin}) {
1.398 raeburn 6090: push(@{$brcrum},
6091: {href => '/adm/createuser?action=selfenroll',
6092: text => "Configure Self-enrollment",
6093: help => 'Course_Self_Enrollment'});
6094: if (!exists($env{'form.state'})) {
6095: $args = { bread_crumbs => $brcrum,
6096: bread_crumbs_component => 'Configure Self-enrollment'};
6097: $r->print(&header(undef,$args));
6098: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6099: &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings);
6100: } elsif ($env{'form.state'} eq 'done') {
6101: push (@{$brcrum},
6102: {href=>'/adm/createuser?action=selfenroll',
6103: text=>"Result"});
6104: $args = { bread_crumbs => $brcrum,
6105: bread_crumbs_component => 'Self-enrollment result'};
6106: $r->print(&header(undef,$args));
6107: $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
1.400 raeburn 6108: &update_selfenroll_config($r,$cid,$cdom,$cnum,$context,$crstype,\%currsettings);
1.398 raeburn 6109: }
1.406.2.20.2. (raeburn 6110:): } elsif ($permission->{selfenrollview}) {
6111:): push(@{$brcrum},
6112:): {href => '/adm/createuser?action=selfenroll',
6113:): text => "View Self-enrollment configuration",
6114:): help => 'Course_Self_Enrollment'});
6115:): $args = { bread_crumbs => $brcrum,
6116:): bread_crumbs_component => 'Self-enrollment Settings'};
6117:): $r->print(&header(undef,$args));
6118:): $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
6119:): &print_selfenroll_menu($r,'course',$cid,$cdom,$cnum,\%currsettings,'',1);
1.398 raeburn 6120: } else {
6121: $r->print(&header(undef,{'no_nav_bar' => 1}).
6122: '<span class="LC_error">'.&mt('You do not have permission to configure self-enrollment').'</span>');
1.237 raeburn 6123: }
1.277 raeburn 6124: } elsif ($env{'form.action'} eq 'selfenrollqueue') {
1.406.2.6 raeburn 6125: if ($permission->{selfenrolladmin}) {
1.351 raeburn 6126: push(@{$brcrum},
6127: {href => '/adm/createuser?action=selfenrollqueue',
1.406.2.6 raeburn 6128: text => 'Enrollment requests',
1.406.2.14 raeburn 6129: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 6130: $bread_crumbs_component = 'Enrollment requests';
6131: if ($env{'form.state'} eq 'done') {
6132: push(@{$brcrum},
6133: {href => '/adm/createuser?action=selfenrollqueue',
6134: text => 'Result',
1.406.2.14 raeburn 6135: help => 'Course_Approve_Selfenroll'});
1.406.2.6 raeburn 6136: $bread_crumbs_component = 'Enrollment result';
6137: }
6138: $args = { bread_crumbs => $brcrum,
6139: bread_crumbs_component => $bread_crumbs_component};
6140: $r->print(&header(undef,$args));
6141: my $coursedesc = $env{'course.'.$cid.'.description'};
6142: if (!exists($env{'form.state'})) {
6143: $r->print('<h3>'.&mt('Pending enrollment requests').'</h3>'."\n");
6144: $r->print(&Apache::loncoursequeueadmin::display_queued_requests($context,
6145: $cdom,$cnum));
6146: } elsif ($env{'form.state'} eq 'done') {
6147: $r->print('<h3>'.&mt('Enrollment request processing').'</h3>'."\n");
6148: $r->print(&Apache::loncoursequeueadmin::update_request_queue($context,
6149: $cdom,$cnum,$coursedesc));
6150: }
6151: } else {
6152: $r->print(&header(undef,{'no_nav_bar' => 1}).
6153: '<span class="LC_error">'.&mt('You do not have permission to manage self-enrollment').'</span>');
1.277 raeburn 6154: }
1.239 raeburn 6155: } elsif ($env{'form.action'} eq 'changelogs') {
1.406.2.6 raeburn 6156: if ($permission->{cusr} || $permission->{view}) {
6157: &print_userchangelogs_display($r,$context,$permission,$brcrum);
6158: } else {
6159: $r->print(&header(undef,{'no_nav_bar' => 1}).
6160: '<span class="LC_error">'.&mt('You do not have permission to view change logs').'</span>');
6161: }
1.406.2.10 raeburn 6162: } elsif ($env{'form.action'} eq 'helpdesk') {
1.406.2.20.2. (raeburn 6163:): if (($permission->{'owner'} || $permission->{'co-owner'}) &&
6164:): ($permission->{'cusr'} || $permission->{'view'})) {
1.406.2.10 raeburn 6165: if ($env{'form.state'} eq 'process') {
6166: if ($permission->{'owner'}) {
6167: &update_helpdeskaccess($r,$permission,$brcrum);
6168: } else {
6169: &print_helpdeskaccess_display($r,$permission,$brcrum);
6170: }
6171: } else {
6172: &print_helpdeskaccess_display($r,$permission,$brcrum);
6173: }
6174: } else {
6175: $r->print(&header(undef,{'no_nav_bar' => 1}).
6176: '<span class="LC_error">'.&mt('You do not have permission to view helpdesk access').'</span>');
6177: }
1.406.2.20.2. (raeburn 6178:): } elsif ($env{'form.action'} eq 'camanagers') {
6179:): if (($permission->{cusr}) && ($context eq 'author')) {
6180:): push(@{$brcrum},
6181:): {href => '/adm/createuser?action=camanagers',
6182:): text => 'Co-author Managers',
6183:): help => 'Author_Manage_Coauthors'});
6184:): if ($env{'form.state'} eq 'process') {
6185:): push(@{$brcrum},
6186:): {href => '/adm/createuser?action=camanagers',
6187:): text => 'Result',
6188:): help => 'Author_Manage_Coauthors'});
6189:): }
6190:): $args = { bread_crumbs => $brcrum };
6191:): $r->print(&header(undef,$args));
6192:): my $coursedesc = $env{'course.'.$cid.'.description'};
6193:): if (!exists($env{'form.state'})) {
6194:): $r->print('<h3>'.&mt('Co-author Management').'</h3>'."\n".
6195:): &display_coauthor_managers($permission));
6196:): } elsif ($env{'form.state'} eq 'process') {
6197:): $r->print('<h3>'.&mt('Co-author Management Update Result').'</h3>'."\n".
6198:): &update_coauthor_managers($permission));
6199:): }
6200:): }
6201:): } elsif (($env{'form.action'} eq 'calist') && ($context eq 'author')) {
6202:): if ($permission->{'cusr'}) {
6203:): my ($role,$audom,$auname,$canview,$canedit) =
6204:): &Apache::lonviewcoauthors::get_allowable();
6205:): if (($canedit) && ($env{'form.forceedit'})) {
6206:): &Apache::lonviewcoauthors::get_editor_crumbs($brcrum,'/adm/createuser');
6207:): my $args = { 'bread_crumbs' => $brcrum };
6208:): $r->print(&Apache::loncommon::start_page('Configure co-author listing',undef,
6209:): $args).
6210:): &Apache::lonviewcoauthors::edit_settings($audom,$auname,$role,
6211:): '/adm/createuser'));
6212:): } else {
6213:): push(@{$brcrum},
6214:): {href => '/adm/createuser?action=calist',
6215:): text => 'Coauthor-viewable list',
6216:): help => 'Author_List_Coauthors'});
6217:): my $args = { 'bread_crumbs' => $brcrum };
6218:): $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6219:): $args));
6220:): my %viewsettings =
6221:): &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6222:): if ($viewsettings{'show'} eq 'none') {
6223:): $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6224:): '<p class="LC_info">'.
6225:): &mt('Listing of co-authors not enabled for this Authoring Space').
6226:): '</p>');
6227:): } else {
6228:): &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6229:): '/adm/createuser',\%viewsettings);
6230:): }
6231:): }
6232:): } else {
6233:): $r->internal_redirect('/adm/viewcoauthors');
6234:): return OK;
6235:): }
6236:): } elsif (($env{'form.action'} eq 'setenv') && ($context eq 'author')) {
6237:): my ($role,$audom,$auname,$canview,$canedit) =
6238:): &Apache::lonviewcoauthors::get_allowable();
6239:): push(@{$brcrum},
6240:): {href => '/adm/createuser?action=calist',
6241:): text => 'Coauthor-viewable list',
6242:): help => 'Author_List_Coauthors'});
6243:): my $args = { 'bread_crumbs' => $brcrum };
6244:): $r->print(&Apache::loncommon::start_page('Coauthor-viewable list',undef,
6245:): $args));
6246:): my %viewsettings =
6247:): &Apache::lonviewcoauthors::retrieve_view_settings($auname,$audom,$role);
6248:): if ($viewsettings{'show'} eq 'none') {
6249:): $r->print('<h3>'.&mt('Coauthor-viewable listing').'</h3>'.
6250:): '<p class="LC_info">'.
6251:): &mt('Listing of co-authors not enabled for this Authoring Space').
6252:): '</p>');
6253:): } else {
6254:): &Apache::lonviewcoauthors::print_coauthors($r,$auname,$audom,$role,
6255:): '/adm/createuser',\%viewsettings);
6256:): }
1.190 raeburn 6257: } else {
1.351 raeburn 6258: $bread_crumbs_component = 'User Management';
6259: $args = { bread_crumbs => $brcrum,
6260: bread_crumbs_component => $bread_crumbs_component};
6261: $r->print(&header(undef,$args));
1.318 raeburn 6262: $r->print(&print_main_menu($permission,$context,$crstype));
1.190 raeburn 6263: }
1.351 raeburn 6264: $r->print(&Apache::loncommon::end_page());
1.190 raeburn 6265: return OK;
6266: }
6267:
6268: sub header {
1.351 raeburn 6269: my ($jscript,$args) = @_;
1.190 raeburn 6270: my $start_page;
1.351 raeburn 6271: if (ref($args) eq 'HASH') {
6272: $start_page=&Apache::loncommon::start_page('User Management',$jscript,$args);
1.190 raeburn 6273: } else {
1.351 raeburn 6274: $start_page=&Apache::loncommon::start_page('User Management',$jscript);
1.190 raeburn 6275: }
6276: return $start_page;
6277: }
1.2 www 6278:
1.191 raeburn 6279: sub add_script {
6280: my ($js) = @_;
1.301 bisitz 6281: return '<script type="text/javascript">'."\n"
6282: .'// <![CDATA['."\n"
6283: .$js."\n"
6284: .'// ]]>'."\n"
6285: .'</script>'."\n";
1.191 raeburn 6286: }
6287:
1.391 raeburn 6288: sub usernamerequest_javascript {
6289: my $js = <<ENDJS;
6290:
6291: function openusernamereqdisplay(dom,uname,queue) {
6292: var url = '/adm/createuser?action=displayuserreq';
6293: url += '&domain='+dom+'&username='+uname+'&queue='+queue;
6294: var title = 'Account_Request_Browser';
6295: var options = 'scrollbars=1,resizable=1,menubar=0';
6296: options += ',width=700,height=600';
6297: var stdeditbrowser = open(url,title,options,'1');
6298: stdeditbrowser.focus();
6299: return;
6300: }
6301:
6302: ENDJS
6303: }
6304:
6305: sub close_popup_form {
6306: my $close= &mt('Close Window');
6307: return << "END";
6308: <p><form name="displayreq" action="" method="post">
6309: <input type="button" name="closeme" value="$close" onclick="javascript:self.close();" />
6310: </form></p>
6311: END
6312: }
6313:
1.202 raeburn 6314: sub verify_user_display {
1.364 raeburn 6315: my ($context) = @_;
1.374 raeburn 6316: my %lt = &Apache::lonlocal::texthash (
6317: course => 'course(s): description, section(s), status',
6318: community => 'community(s): description, section(s), status',
6319: author => 'author',
6320: );
1.364 raeburn 6321: my $photos;
6322: if (($context eq 'course') && $env{'request.course.id'}) {
6323: $photos = $env{'course.'.$env{'request.course.id'}.'.internal.showphoto'};
6324: }
1.202 raeburn 6325: my $output = <<"END";
6326:
1.364 raeburn 6327: function hide_searching() {
6328: if (document.getElementById('searching')) {
6329: document.getElementById('searching').style.display = 'none';
6330: }
6331: return;
6332: }
6333:
1.202 raeburn 6334: function display_update() {
6335: document.studentform.action.value = 'listusers';
6336: document.studentform.phase.value = 'display';
6337: document.studentform.submit();
6338: }
6339:
1.364 raeburn 6340: function updateCols(caller) {
6341: var context = '$context';
6342: var photos = '$photos';
6343: if (caller == 'Status') {
1.374 raeburn 6344: if ((context == 'domain') &&
6345: ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6346: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community'))) {
1.364 raeburn 6347: document.getElementById('showcolstatus').checked = false;
6348: document.getElementById('showcolstatus').disabled = 'disabled';
6349: document.getElementById('showcolstart').checked = false;
6350: document.getElementById('showcolend').checked = false;
1.374 raeburn 6351: } else {
6352: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6353: document.getElementById('showcolstatus').checked = true;
6354: document.getElementById('showcolstatus').disabled = '';
6355: document.getElementById('showcolstart').checked = true;
6356: document.getElementById('showcolend').checked = true;
6357: } else {
6358: document.getElementById('showcolstatus').checked = false;
6359: document.getElementById('showcolstatus').disabled = 'disabled';
6360: document.getElementById('showcolstart').checked = false;
6361: document.getElementById('showcolend').checked = false;
6362: }
1.406.2.20.2. (raeburn 6363:): if (context == 'author') {
6364:): if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Expired') {
6365:): document.getElementById('showcolmanager').checked = false;
6366:): document.getElementById('showcolmanager').disabled = 'disabled';
6367:): } else if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value != 'aa') {
6368:): document.getElementById('showcolmanager').checked = true;
6369:): document.getElementById('showcolmanager').disabled = '';
6370:): }
6371:): }
1.364 raeburn 6372: }
6373: }
6374: if (caller == 'output') {
6375: if (photos == 1) {
6376: if (document.getElementById('showcolphoto')) {
6377: var photoitem = document.getElementById('showcolphoto');
6378: if (document.studentform.output.options[document.studentform.output.selectedIndex].value == 'html') {
6379: photoitem.checked = true;
6380: photoitem.disabled = '';
6381: } else {
6382: photoitem.checked = false;
6383: photoitem.disabled = 'disabled';
6384: }
6385: }
6386: }
6387: }
6388: if (caller == 'showrole') {
1.371 raeburn 6389: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any') ||
6390: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'cr')) {
1.364 raeburn 6391: document.getElementById('showcolrole').checked = true;
6392: document.getElementById('showcolrole').disabled = '';
6393: } else {
6394: document.getElementById('showcolrole').checked = false;
6395: document.getElementById('showcolrole').disabled = 'disabled';
6396: }
1.374 raeburn 6397: if (context == 'domain') {
1.382 raeburn 6398: var quotausageshow = 0;
1.374 raeburn 6399: if ((document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'course') ||
6400: (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community')) {
6401: document.getElementById('showcolstatus').checked = false;
6402: document.getElementById('showcolstatus').disabled = 'disabled';
6403: document.getElementById('showcolstart').checked = false;
6404: document.getElementById('showcolend').checked = false;
6405: } else {
6406: if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value == 'Any') {
6407: document.getElementById('showcolstatus').checked = true;
6408: document.getElementById('showcolstatus').disabled = '';
6409: document.getElementById('showcolstart').checked = true;
6410: document.getElementById('showcolend').checked = true;
6411: }
6412: }
6413: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'domain') {
6414: document.getElementById('showcolextent').disabled = 'disabled';
6415: document.getElementById('showcolextent').checked = 'false';
6416: document.getElementById('showextent').style.display='none';
6417: document.getElementById('showcoltextextent').innerHTML = '';
1.382 raeburn 6418: if ((document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'au') ||
6419: (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'Any')) {
6420: if (document.getElementById('showcolauthorusage')) {
6421: document.getElementById('showcolauthorusage').disabled = '';
6422: }
6423: if (document.getElementById('showcolauthorquota')) {
6424: document.getElementById('showcolauthorquota').disabled = '';
6425: }
6426: quotausageshow = 1;
6427: }
1.374 raeburn 6428: } else {
6429: document.getElementById('showextent').style.display='block';
6430: document.getElementById('showextent').style.textAlign='left';
6431: document.getElementById('showextent').style.textFace='normal';
6432: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'author') {
6433: document.getElementById('showcolextent').disabled = '';
6434: document.getElementById('showcolextent').checked = 'true';
6435: document.getElementById('showcoltextextent').innerHTML="$lt{'author'}";
6436: } else {
6437: document.getElementById('showcolextent').disabled = '';
6438: document.getElementById('showcolextent').checked = 'true';
6439: if (document.studentform.roletype.options[document.studentform.roletype.selectedIndex].value == 'community') {
6440: document.getElementById('showcoltextextent').innerHTML="$lt{'community'}";
6441: } else {
6442: document.getElementById('showcoltextextent').innerHTML="$lt{'course'}";
6443: }
6444: }
6445: }
1.382 raeburn 6446: if (quotausageshow == 0) {
6447: if (document.getElementById('showcolauthorusage')) {
6448: document.getElementById('showcolauthorusage').checked = false;
6449: document.getElementById('showcolauthorusage').disabled = 'disabled';
6450: }
6451: if (document.getElementById('showcolauthorquota')) {
6452: document.getElementById('showcolauthorquota').checked = false;
6453: document.getElementById('showcolauthorquota').disabled = 'disabled';
6454: }
6455: }
1.374 raeburn 6456: }
1.406.2.20.2. (raeburn 6457:): if (context == 'author') {
6458:): if (document.studentform.showrole.options[document.studentform.showrole.selectedIndex].value == 'aa') {
6459:): document.getElementById('showcolmanager').checked = false;
6460:): document.getElementById('showcolmanager').disabled = 'disabled';
6461:): } else if (document.studentform.Status.options[document.studentform.Status.selectedIndex].value != 'Expired') {
6462:): document.getElementById('showcolmanager').checked = true;
6463:): document.getElementById('showcolmanager').disabled = '';
6464:): }
6465:): }
1.364 raeburn 6466: }
6467: return;
6468: }
6469:
1.202 raeburn 6470: END
6471: return $output;
6472:
6473: }
6474:
1.190 raeburn 6475: ###############################################################
6476: ###############################################################
6477: # Menu Phase One
6478: sub print_main_menu {
1.318 raeburn 6479: my ($permission,$context,$crstype) = @_;
6480: my $linkcontext = $context;
6481: my $stuterm = lc(&Apache::lonnet::plaintext('st',$crstype));
6482: if (($context eq 'course') && ($crstype eq 'Community')) {
6483: $linkcontext = lc($crstype);
6484: $stuterm = 'Members';
6485: }
1.208 raeburn 6486: my %links = (
1.298 droeschl 6487: domain => {
6488: upload => 'Upload a File of Users',
6489: singleuser => 'Add/Modify a User',
6490: listusers => 'Manage Users',
6491: },
6492: author => {
6493: upload => 'Upload a File of Co-authors',
6494: singleuser => 'Add/Modify a Co-author',
6495: listusers => 'Manage Co-authors',
6496: },
6497: course => {
6498: upload => 'Upload a File of Course Users',
6499: singleuser => 'Add/Modify a Course User',
1.354 www 6500: listusers => 'List and Modify Multiple Course Users',
1.298 droeschl 6501: },
1.318 raeburn 6502: community => {
6503: upload => 'Upload a File of Community Users',
6504: singleuser => 'Add/Modify a Community User',
1.354 www 6505: listusers => 'List and Modify Multiple Community Users',
1.318 raeburn 6506: },
6507: );
6508: my %linktitles = (
6509: domain => {
6510: singleuser => 'Add a user to the domain, and/or a course or community in the domain.',
6511: listusers => 'Show and manage users in this domain.',
6512: },
6513: author => {
6514: singleuser => 'Add a user with a co- or assistant author role.',
6515: listusers => 'Show and manage co- or assistant authors.',
6516: },
6517: course => {
6518: singleuser => 'Add a user with a certain role to this course.',
6519: listusers => 'Show and manage users in this course.',
6520: },
6521: community => {
6522: singleuser => 'Add a user with a certain role to this community.',
6523: listusers => 'Show and manage users in this community.',
6524: },
1.298 droeschl 6525: );
1.406.2.6 raeburn 6526: if ($linkcontext eq 'domain') {
6527: unless ($permission->{'cusr'}) {
6528: $links{'domain'}{'singleuser'} = 'View a User';
6529: $linktitles{'domain'}{'singleuser'} = 'View information about a user in the domain';
6530: }
6531: } elsif ($linkcontext eq 'course') {
6532: unless ($permission->{'cusr'}) {
6533: $links{'course'}{'singleuser'} = 'View a Course User';
6534: $linktitles{'course'}{'singleuser'} = 'View information about a user in this course';
6535: $links{'course'}{'listusers'} = 'List Course Users';
6536: $linktitles{'course'}{'listusers'} = 'Show information about users in this course';
6537: }
6538: } elsif ($linkcontext eq 'community') {
6539: unless ($permission->{'cusr'}) {
6540: $links{'community'}{'singleuser'} = 'View a Community User';
6541: $linktitles{'community'}{'singleuser'} = 'View information about a user in this community';
6542: $links{'community'}{'listusers'} = 'List Community Users';
6543: $linktitles{'community'}{'listusers'} = 'Show information about users in this community';
6544: }
6545: }
1.298 droeschl 6546: my @menu = ( {categorytitle => 'Single Users',
6547: items =>
6548: [
6549: {
1.318 raeburn 6550: linktext => $links{$linkcontext}{'singleuser'},
1.298 droeschl 6551: icon => 'edit-redo.png',
6552: #help => 'Course_Change_Privileges',
6553: url => '/adm/createuser?action=singleuser',
1.406.2.6 raeburn 6554: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6555: linktitle => $linktitles{$linkcontext}{'singleuser'},
1.298 droeschl 6556: },
6557: ]},
6558:
6559: {categorytitle => 'Multiple Users',
6560: items =>
6561: [
6562: {
1.318 raeburn 6563: linktext => $links{$linkcontext}{'upload'},
1.340 wenzelju 6564: icon => 'uplusr.png',
1.298 droeschl 6565: #help => 'Course_Create_Class_List',
6566: url => '/adm/createuser?action=upload',
6567: permission => $permission->{'cusr'},
6568: linktitle => 'Upload a CSV or a text file containing users.',
6569: },
6570: {
1.318 raeburn 6571: linktext => $links{$linkcontext}{'listusers'},
1.340 wenzelju 6572: icon => 'mngcu.png',
1.298 droeschl 6573: #help => 'Course_View_Class_List',
6574: url => '/adm/createuser?action=listusers',
6575: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.318 raeburn 6576: linktitle => $linktitles{$linkcontext}{'listusers'},
1.298 droeschl 6577: },
6578:
6579: ]},
6580:
6581: {categorytitle => 'Administration',
6582: items => [ ]},
6583: );
1.406.2.5 raeburn 6584:
1.265 mielkec 6585: if ($context eq 'domain'){
1.406.2.5 raeburn 6586: push(@{ $menu[0]->{items} }, # Single Users
6587: {
6588: linktext => 'User Access Log',
6589: icon => 'document-properties.png',
1.406.2.8 raeburn 6590: #help => 'Domain_User_Access_Logs',
1.406.2.5 raeburn 6591: url => '/adm/createuser?action=accesslogs',
6592: permission => $permission->{'activity'},
6593: linktitle => 'View user access log.',
6594: }
6595: );
1.298 droeschl 6596:
6597: push(@{ $menu[2]->{items} }, #Category: Administration
6598: {
6599: linktext => 'Custom Roles',
6600: icon => 'emblem-photos.png',
6601: #help => 'Course_Editing_Custom_Roles',
6602: url => '/adm/createuser?action=custom',
6603: permission => $permission->{'custom'},
6604: linktitle => 'Configure a custom role.',
6605: },
1.362 raeburn 6606: {
6607: linktext => 'Authoring Space Requests',
6608: icon => 'selfenrl-queue.png',
6609: #help => 'Domain_Role_Approvals',
6610: url => '/adm/createuser?action=processauthorreq',
6611: permission => $permission->{'cusr'},
6612: linktitle => 'Approve or reject author role requests',
6613: },
1.363 raeburn 6614: {
1.391 raeburn 6615: linktext => 'LON-CAPA Account Requests',
6616: icon => 'list-add.png',
6617: #help => 'Domain_Username_Approvals',
6618: url => '/adm/createuser?action=processusernamereq',
6619: permission => $permission->{'cusr'},
6620: linktitle => 'Approve or reject LON-CAPA account requests',
6621: },
6622: {
1.363 raeburn 6623: linktext => 'Change Log',
6624: icon => 'document-properties.png',
6625: #help => 'Course_User_Logs',
6626: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 6627: permission => ($permission->{'cusr'} || $permission->{'view'}),
1.363 raeburn 6628: linktitle => 'View change log.',
6629: },
1.298 droeschl 6630: );
6631:
1.265 mielkec 6632: }elsif ($context eq 'course'){
1.298 droeschl 6633: my ($cnum,$cdom) = &Apache::lonuserutils::get_course_identity();
1.318 raeburn 6634:
6635: my %linktext = (
6636: 'Course' => {
6637: single => 'Add/Modify a Student',
6638: drop => 'Drop Students',
6639: groups => 'Course Groups',
6640: },
6641: 'Community' => {
6642: single => 'Add/Modify a Member',
6643: drop => 'Drop Members',
6644: groups => 'Community Groups',
6645: },
6646: );
6647:
6648: my %linktitle = (
6649: 'Course' => {
6650: single => 'Add a user with the role of student to this course',
6651: drop => 'Remove a student from this course.',
6652: groups => 'Manage course groups',
6653: },
6654: 'Community' => {
6655: single => 'Add a user with the role of member to this community',
6656: drop => 'Remove a member from this community.',
6657: groups => 'Manage community groups',
6658: },
6659: );
6660:
1.298 droeschl 6661: push(@{ $menu[0]->{items} }, #Category: Single Users
6662: {
1.318 raeburn 6663: linktext => $linktext{$crstype}{'single'},
1.298 droeschl 6664: #help => 'Course_Add_Student',
6665: icon => 'list-add.png',
6666: url => '/adm/createuser?action=singlestudent',
6667: permission => $permission->{'cusr'},
1.318 raeburn 6668: linktitle => $linktitle{$crstype}{'single'},
1.298 droeschl 6669: },
6670: );
6671:
6672: push(@{ $menu[1]->{items} }, #Category: Multiple Users
6673: {
1.318 raeburn 6674: linktext => $linktext{$crstype}{'drop'},
1.298 droeschl 6675: icon => 'edit-undo.png',
6676: #help => 'Course_Drop_Student',
6677: url => '/adm/createuser?action=drop',
6678: permission => $permission->{'cusr'},
1.318 raeburn 6679: linktitle => $linktitle{$crstype}{'drop'},
1.298 droeschl 6680: },
6681: );
6682: push(@{ $menu[2]->{items} }, #Category: Administration
1.406.2.11 raeburn 6683: {
6684: linktext => 'Helpdesk Access',
6685: icon => 'helpdesk-access.png',
6686: #help => 'Course_Helpdesk_Access',
6687: url => '/adm/createuser?action=helpdesk',
1.406.2.20.2. (raeburn 6688:): permission => (($permission->{'owner'} || $permission->{'co-owner'}) &&
6689:): ($permission->{'view'} || $permission->{'cusr'})),
1.406.2.11 raeburn 6690: linktitle => 'Helpdesk access options',
6691: },
6692: {
1.298 droeschl 6693: linktext => 'Custom Roles',
6694: icon => 'emblem-photos.png',
6695: #help => 'Course_Editing_Custom_Roles',
6696: url => '/adm/createuser?action=custom',
6697: permission => $permission->{'custom'},
6698: linktitle => 'Configure a custom role.',
6699: },
6700: {
1.318 raeburn 6701: linktext => $linktext{$crstype}{'groups'},
1.333 wenzelju 6702: icon => 'grps.png',
1.298 droeschl 6703: #help => 'Course_Manage_Group',
6704: url => '/adm/coursegroups?refpage=cusr',
6705: permission => $permission->{'grp_manage'},
1.318 raeburn 6706: linktitle => $linktitle{$crstype}{'groups'},
1.298 droeschl 6707: },
6708: {
1.328 wenzelju 6709: linktext => 'Change Log',
1.298 droeschl 6710: icon => 'document-properties.png',
6711: #help => 'Course_User_Logs',
6712: url => '/adm/createuser?action=changelogs',
1.406.2.6 raeburn 6713: permission => ($permission->{'view'} || $permission->{'cusr'}),
1.298 droeschl 6714: linktitle => 'View change log.',
6715: },
6716: );
1.277 raeburn 6717: if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_approval'}) {
1.298 droeschl 6718: push(@{ $menu[2]->{items} },
1.398 raeburn 6719: {
1.298 droeschl 6720: linktext => 'Enrollment Requests',
6721: icon => 'selfenrl-queue.png',
6722: #help => 'Course_Approve_Selfenroll',
6723: url => '/adm/createuser?action=selfenrollqueue',
1.406.2.20.2. (raeburn 6724:): permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.298 droeschl 6725: linktitle =>'Approve or reject enrollment requests.',
6726: },
6727: );
1.277 raeburn 6728: }
1.298 droeschl 6729:
1.265 mielkec 6730: if (!exists($permission->{'cusr_section'})){
1.320 raeburn 6731: if ($crstype ne 'Community') {
6732: push(@{ $menu[2]->{items} },
6733: {
6734: linktext => 'Automated Enrollment',
6735: icon => 'roles.png',
6736: #help => 'Course_Automated_Enrollment',
6737: permission => (&Apache::lonnet::auto_run($cnum,$cdom)
1.406.2.6 raeburn 6738: && (($permission->{'cusr'}) ||
6739: ($permission->{'view'}))),
1.320 raeburn 6740: url => '/adm/populate',
6741: linktitle => 'Automated enrollment manager.',
6742: }
6743: );
6744: }
6745: push(@{ $menu[2]->{items} },
1.298 droeschl 6746: {
6747: linktext => 'User Self-Enrollment',
1.342 wenzelju 6748: icon => 'self_enroll.png',
1.298 droeschl 6749: #help => 'Course_Self_Enrollment',
6750: url => '/adm/createuser?action=selfenroll',
1.406.2.20.2. (raeburn 6751:): permission => $permission->{'selfenrolladmin'} || $permission->{'selfenrollview'},
1.317 bisitz 6752: linktitle => 'Configure user self-enrollment.',
1.298 droeschl 6753: },
6754: );
6755: }
1.363 raeburn 6756: } elsif ($context eq 'author') {
1.406.2.20.2. (raeburn 6757:): my $coauthorlist;
6758:): if ($env{'request.role'} =~ m{^(?:ca|aa)\./($match_domain)/($match_username)$}) {
6759:): if ($env{'environment.internal.coauthorlist./'.$1.'/'.$2}) {
6760:): $coauthorlist = 1;
6761:): }
6762:): } elsif ($env{'request.role'} eq "au./$env{'user.domain'}/") {
6763:): if ($env{'environment.coauthorlist'}) {
6764:): $coauthorlist = 1;
6765:): }
6766:): }
6767:): if ($coauthorlist) {
6768:): push(@{ $menu[1]->{items} },
6769:): {
6770:): linktext => 'Co-author-viewable list',
6771:): icon => 'clst.png',
6772:): #help => 'Coauthor_Listing',
6773:): url => '/adm/createuser?action=calist&forceedit=0',
6774:): permission => $permission->{'cusr'},
6775:): linktitle => 'Co-author-viewable listing',
6776:): });
6777:): }
1.370 raeburn 6778: push(@{ $menu[2]->{items} }, #Category: Administration
1.363 raeburn 6779: {
6780: linktext => 'Change Log',
6781: icon => 'document-properties.png',
6782: #help => 'Course_User_Logs',
6783: url => '/adm/createuser?action=changelogs',
6784: permission => $permission->{'cusr'},
6785: linktitle => 'View change log.',
6786: },
1.406.2.20.2. (raeburn 6787:): {
6788:): linktext => 'Co-author Managers',
6789:): icon => 'camanager.png',
6790:): #help => 'Coauthor_Management',
6791:): url => '/adm/createuser?action=camanagers',
6792:): permission => $permission->{'author'},
6793:): linktitle => 'Assign/Revoke right to manage co-author roles',
6794:): },
6795:): {
6796:): linktext => 'Configure Co-author Listing',
6797:): icon => 'coauthors.png',
6798:): #help => 'Coauthor_Settings',
6799:): url => '/adm/createuser?action=calist&forceedit=1',
6800:): permission => ($permission->{'cusr'}),
6801:): linktitle => 'Set availability of coauthor-viewable user listing',
6802:): },
1.370 raeburn 6803: );
1.363 raeburn 6804: }
6805: return Apache::lonhtmlcommon::generate_menu(@menu);
1.250 raeburn 6806: # { text => 'View Log-in History',
6807: # help => 'Course_User_Logins',
6808: # action => 'logins',
6809: # permission => $permission->{'cusr'},
6810: # });
1.190 raeburn 6811: }
6812:
1.189 albertel 6813: sub restore_prev_selections {
6814: my %saveable_parameters = ('srchby' => 'scalar',
6815: 'srchin' => 'scalar',
6816: 'srchtype' => 'scalar',
6817: );
6818: &Apache::loncommon::store_settings('user','user_picker',
6819: \%saveable_parameters);
6820: &Apache::loncommon::restore_settings('user','user_picker',
6821: \%saveable_parameters);
6822: }
6823:
1.237 raeburn 6824: sub print_selfenroll_menu {
1.406.2.6 raeburn 6825: my ($r,$context,$cid,$cdom,$cnum,$currsettings,$additional,$readonly) = @_;
1.322 raeburn 6826: my $crstype = &Apache::loncommon::course_type();
1.398 raeburn 6827: my $formname = 'selfenroll';
1.237 raeburn 6828: my $nolink = 1;
1.398 raeburn 6829: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
1.237 raeburn 6830: my $groupslist = &Apache::lonuserutils::get_groupslist();
6831: my $setsec_js =
6832: &Apache::lonuserutils::setsections_javascript($formname,$groupslist);
1.249 raeburn 6833: my %alerts = &Apache::lonlocal::texthash(
6834: acto => 'Activation of self-enrollment was selected for the following domain(s)',
6835: butn => 'but no user types have been checked.',
6836: wilf => "Please uncheck 'activate' or check at least one type.",
6837: );
1.406.2.6 raeburn 6838: my $disabled;
6839: if ($readonly) {
6840: $disabled = ' disabled="disabled"';
6841: }
1.405 damieng 6842: &js_escape(\%alerts);
1.249 raeburn 6843: my $selfenroll_js = <<"ENDSCRIPT";
6844: function update_types(caller,num) {
6845: var delidx = getIndexByName('selfenroll_delete');
6846: var actidx = getIndexByName('selfenroll_activate');
6847: if (caller == 'selfenroll_all') {
6848: var selall;
6849: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6850: if (document.$formname.selfenroll_all[i].checked) {
6851: selall = document.$formname.selfenroll_all[i].value;
6852: }
6853: }
6854: if (selall == 1) {
6855: if (delidx != -1) {
6856: if (document.$formname.selfenroll_delete.length) {
6857: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
6858: document.$formname.selfenroll_delete[j].checked = true;
6859: }
6860: } else {
6861: document.$formname.elements[delidx].checked = true;
6862: }
6863: }
6864: if (actidx != -1) {
6865: if (document.$formname.selfenroll_activate.length) {
6866: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6867: document.$formname.selfenroll_activate[j].checked = false;
6868: }
6869: } else {
6870: document.$formname.elements[actidx].checked = false;
6871: }
6872: }
6873: document.$formname.selfenroll_newdom.selectedIndex = 0;
6874: }
6875: }
6876: if (caller == 'selfenroll_activate') {
6877: if (document.$formname.selfenroll_activate.length) {
6878: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6879: if (document.$formname.selfenroll_activate[j].value == num) {
6880: if (document.$formname.selfenroll_activate[j].checked) {
6881: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6882: if (document.$formname.selfenroll_all[i].value == '1') {
6883: document.$formname.selfenroll_all[i].checked = false;
6884: }
6885: if (document.$formname.selfenroll_all[i].value == '0') {
6886: document.$formname.selfenroll_all[i].checked = true;
6887: }
6888: }
6889: }
6890: }
6891: }
6892: } else {
6893: for (var i=0; i<document.$formname.selfenroll_all.length; i++) {
6894: if (document.$formname.selfenroll_all[i].value == '1') {
6895: document.$formname.selfenroll_all[i].checked = false;
6896: }
6897: if (document.$formname.selfenroll_all[i].value == '0') {
6898: document.$formname.selfenroll_all[i].checked = true;
6899: }
6900: }
6901: }
6902: }
6903: if (caller == 'selfenroll_delete') {
6904: if (document.$formname.selfenroll_delete.length) {
6905: for (var j=0; j<document.$formname.selfenroll_delete.length; j++) {
6906: if (document.$formname.selfenroll_delete[j].value == num) {
6907: if (document.$formname.selfenroll_delete[j].checked) {
6908: var delindex = getIndexByName('selfenroll_types_'+num);
6909: if (delindex != -1) {
6910: if (document.$formname.elements[delindex].length) {
6911: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6912: document.$formname.elements[delindex][k].checked = false;
6913: }
6914: } else {
6915: document.$formname.elements[delindex].checked = false;
6916: }
6917: }
6918: }
6919: }
6920: }
6921: } else {
6922: if (document.$formname.selfenroll_delete.checked) {
6923: var delindex = getIndexByName('selfenroll_types_'+num);
6924: if (delindex != -1) {
6925: if (document.$formname.elements[delindex].length) {
6926: for (var k=0; k<document.$formname.elements[delindex].length; k++) {
6927: document.$formname.elements[delindex][k].checked = false;
6928: }
6929: } else {
6930: document.$formname.elements[delindex].checked = false;
6931: }
6932: }
6933: }
6934: }
6935: }
6936: return;
6937: }
6938:
6939: function validate_types(form) {
6940: var needaction = new Array();
6941: var countfail = 0;
6942: var actidx = getIndexByName('selfenroll_activate');
6943: if (actidx != -1) {
6944: if (document.$formname.selfenroll_activate.length) {
6945: for (var j=0; j<document.$formname.selfenroll_activate.length; j++) {
6946: var num = document.$formname.selfenroll_activate[j].value;
6947: if (document.$formname.selfenroll_activate[j].checked) {
6948: countfail = check_types(num,countfail,needaction)
6949: }
6950: }
6951: } else {
6952: if (document.$formname.selfenroll_activate.checked) {
1.398 raeburn 6953: var num = document.$formname.selfenroll_activate.value;
1.249 raeburn 6954: countfail = check_types(num,countfail,needaction)
6955: }
6956: }
6957: }
6958: if (countfail > 0) {
6959: var msg = "$alerts{'acto'}\\n";
6960: var loopend = needaction.length -1;
6961: if (loopend > 0) {
6962: for (var m=0; m<loopend; m++) {
6963: msg += needaction[m]+", ";
6964: }
6965: }
6966: msg += needaction[loopend]+"\\n$alerts{'butn'}\\n$alerts{'wilf'}";
6967: alert(msg);
6968: return;
6969: }
6970: setSections(form);
6971: }
6972:
6973: function check_types(num,countfail,needaction) {
1.406.2.15 raeburn 6974: var boxname = 'selfenroll_types_'+num;
6975: var typeidx = getIndexByName(boxname);
1.249 raeburn 6976: var count = 0;
6977: if (typeidx != -1) {
1.406.2.15 raeburn 6978: if (document.$formname.elements[boxname].length) {
6979: for (var k=0; k<document.$formname.elements[boxname].length; k++) {
6980: if (document.$formname.elements[boxname][k].checked) {
1.249 raeburn 6981: count ++;
6982: }
6983: }
6984: } else {
6985: if (document.$formname.elements[typeidx].checked) {
6986: count ++;
6987: }
6988: }
6989: if (count == 0) {
6990: var domidx = getIndexByName('selfenroll_dom_'+num);
6991: if (domidx != -1) {
6992: var domname = document.$formname.elements[domidx].value;
6993: needaction[countfail] = domname;
6994: countfail ++;
6995: }
6996: }
6997: }
6998: return countfail;
6999: }
7000:
1.398 raeburn 7001: function toggleNotify() {
7002: var selfenrollApproval = 0;
7003: if (document.$formname.selfenroll_approval.length) {
7004: for (var i=0; i<document.$formname.selfenroll_approval.length; i++) {
7005: if (document.$formname.selfenroll_approval[i].checked) {
7006: selfenrollApproval = document.$formname.selfenroll_approval[i].value;
7007: break;
7008: }
7009: }
7010: }
7011: if (document.getElementById('notified')) {
7012: if (selfenrollApproval == 0) {
7013: document.getElementById('notified').style.display='none';
7014: } else {
7015: document.getElementById('notified').style.display='block';
7016: }
7017: }
7018: return;
7019: }
7020:
1.249 raeburn 7021: function getIndexByName(item) {
7022: for (var i=0;i<document.$formname.elements.length;i++) {
7023: if (document.$formname.elements[i].name == item) {
7024: return i;
7025: }
7026: }
7027: return -1;
7028: }
7029: ENDSCRIPT
1.256 raeburn 7030:
1.237 raeburn 7031: my $output = '<script type="text/javascript">'."\n".
1.301 bisitz 7032: '// <![CDATA['."\n".
1.249 raeburn 7033: $setsec_js."\n".$selfenroll_js."\n".
1.301 bisitz 7034: '// ]]>'."\n".
1.237 raeburn 7035: '</script>'."\n".
1.256 raeburn 7036: '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n";
1.406.2.20.2. (raeburn 7037:): my $visactions = &cat_visibility($cdom);
1.400 raeburn 7038: my ($cathash,%cattype);
7039: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
7040: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7041: $cathash = $domconfig{'coursecategories'}{'cats'};
7042: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
7043: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
1.406 raeburn 7044: if ($cattype{'auth'} eq '') {
7045: $cattype{'auth'} = 'std';
7046: }
7047: if ($cattype{'unauth'} eq '') {
7048: $cattype{'unauth'} = 'std';
7049: }
1.400 raeburn 7050: } else {
7051: $cathash = {};
7052: $cattype{'auth'} = 'std';
7053: $cattype{'unauth'} = 'std';
7054: }
7055: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
7056: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7057: '<br />'.
7058: '<br />'.$visactions->{'take'}.'<ul>'.
7059: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
7060: '</ul>');
7061: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
7062: if ($currsettings->{'uniquecode'}) {
7063: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
7064: } else {
7065: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
7066: '<br />'.
7067: '<br />'.$visactions->{'take'}.'<ul>'.
7068: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
7069: '</ul><br />');
7070: }
7071: } else {
7072: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
7073: if (ref($visactions) eq 'HASH') {
7074: if ($visible) {
7075: $output .= '<p class="LC_info">'.$visactions->{'vis'}.'</p>';
7076: } else {
7077: $output .= '<p class="LC_warning">'.$visactions->{'miss'}.'</p>'
7078: .$visactions->{'yous'}.
7079: '<p>'.$visactions->{'gen'}.'<br />'.$visactions->{'coca'};
7080: if (ref($vismsgs) eq 'ARRAY') {
7081: $output .= '<br />'.$visactions->{'make'}.'<ul>';
7082: foreach my $item (@{$vismsgs}) {
7083: $output .= '<li>'.$visactions->{$item}.'</li>';
7084: }
7085: $output .= '</ul>';
1.256 raeburn 7086: }
1.400 raeburn 7087: $output .= '</p>';
1.256 raeburn 7088: }
7089: }
7090: }
1.398 raeburn 7091: my $actionhref = '/adm/createuser';
7092: if ($context eq 'domain') {
7093: $actionhref = '/adm/modifycourse';
7094: }
1.400 raeburn 7095:
7096: my %noedit;
7097: unless ($context eq 'domain') {
7098: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
7099: }
1.398 raeburn 7100: $output .= '<form name="'.$formname.'" method="post" action="'.$actionhref.'">'."\n".
1.256 raeburn 7101: &Apache::lonhtmlcommon::start_pick_box();
1.237 raeburn 7102: if (ref($row) eq 'ARRAY') {
7103: foreach my $item (@{$row}) {
7104: my $title = $item;
7105: if (ref($lt) eq 'HASH') {
7106: $title = $lt->{$item};
7107: }
1.297 bisitz 7108: $output .= &Apache::lonhtmlcommon::row_title($title);
1.237 raeburn 7109: if ($item eq 'types') {
1.398 raeburn 7110: my $curr_types;
7111: if (ref($currsettings) eq 'HASH') {
7112: $curr_types = $currsettings->{'selfenroll_types'};
7113: }
1.400 raeburn 7114: if ($noedit{$item}) {
7115: if ($curr_types eq '*') {
7116: $output .= &mt('Any user in any domain');
7117: } else {
7118: my @entries = split(/;/,$curr_types);
7119: if (@entries > 0) {
7120: $output .= '<ul>';
7121: foreach my $entry (@entries) {
7122: my ($currdom,$typestr) = split(/:/,$entry);
7123: next if ($typestr eq '');
7124: my $domdesc = &Apache::lonnet::domain($currdom);
7125: my @currinsttypes = split(',',$typestr);
7126: my ($othertitle,$usertypes,$types) =
7127: &Apache::loncommon::sorted_inst_types($currdom);
7128: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7129: $usertypes->{'any'} = &mt('any user');
7130: if (keys(%{$usertypes}) > 0) {
7131: $usertypes->{'other'} = &mt('other users');
7132: }
7133: my @longinsttypes = map { $usertypes->{$_}; } @currinsttypes;
7134: $output .= '<li>'.$domdesc.':'.join(', ',@longinsttypes).'</li>';
7135: }
7136: }
7137: $output .= '</ul>';
7138: } else {
7139: $output .= &mt('None');
7140: }
7141: }
7142: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7143: next;
7144: }
1.241 raeburn 7145: my $showdomdesc = 1;
7146: my $includeempty = 1;
7147: my $num = 0;
7148: $output .= &Apache::loncommon::start_data_table().
7149: &Apache::loncommon::start_data_table_row()
7150: .'<td colspan="2"><span class="LC_nobreak"><label>'
7151: .&mt('Any user in any domain:')
7152: .' <input type="radio" name="selfenroll_all" value="1" ';
7153: if ($curr_types eq '*') {
7154: $output .= ' checked="checked" ';
7155: }
1.249 raeburn 7156: $output .= 'onchange="javascript:update_types('.
1.406.2.6 raeburn 7157: "'selfenroll_all'".');"'.$disabled.' />'.&mt('Yes').'</label>'.
1.249 raeburn 7158: ' <input type="radio" name="selfenroll_all" value="0" ';
1.241 raeburn 7159: if ($curr_types ne '*') {
7160: $output .= ' checked="checked" ';
7161: }
1.249 raeburn 7162: $output .= ' onchange="javascript:update_types('.
1.406.2.6 raeburn 7163: "'selfenroll_all'".');"'.$disabled.' />'.&mt('No').'</label></td>'.
1.249 raeburn 7164: &Apache::loncommon::end_data_table_row().
7165: &Apache::loncommon::end_data_table().
7166: &mt('Or').'<br />'.
7167: &Apache::loncommon::start_data_table();
1.241 raeburn 7168: my %currdoms;
1.249 raeburn 7169: if ($curr_types eq '') {
1.241 raeburn 7170: $output .= &new_selfenroll_dom_row($cdom,'0');
7171: } elsif ($curr_types ne '*') {
7172: my @entries = split(/;/,$curr_types);
7173: if (@entries > 0) {
7174: foreach my $entry (@entries) {
7175: my ($currdom,$typestr) = split(/:/,$entry);
7176: $currdoms{$currdom} = 1;
7177: my $domdesc = &Apache::lonnet::domain($currdom);
1.249 raeburn 7178: my @currinsttypes = split(',',$typestr);
1.241 raeburn 7179: $output .= &Apache::loncommon::start_data_table_row()
7180: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
7181: .' '.$domdesc.' ('.$currdom.')'
7182: .'</b><input type="hidden" name="selfenroll_dom_'.$num
7183: .'" value="'.$currdom.'" /></span><br />'
7184: .'<span class="LC_nobreak"><label><input type="checkbox" '
1.406.2.6 raeburn 7185: .'name="selfenroll_delete" value="'.$num.'" onchange="javascript:update_types('."'selfenroll_delete','$num'".');"'.$disabled.' />'
1.241 raeburn 7186: .&mt('Delete').'</label></span></td>';
1.249 raeburn 7187: $output .= '<td valign="top"> '.&mt('User types:').'<br />'
1.406.2.6 raeburn 7188: .&selfenroll_inst_types($num,$currdom,\@currinsttypes,$readonly).'</td>'
1.241 raeburn 7189: .&Apache::loncommon::end_data_table_row();
7190: $num ++;
7191: }
7192: }
7193: }
1.249 raeburn 7194: my $add_domtitle = &mt('Users in additional domain:');
1.241 raeburn 7195: if ($curr_types eq '*') {
1.249 raeburn 7196: $add_domtitle = &mt('Users in specific domain:');
1.241 raeburn 7197: } elsif ($curr_types eq '') {
1.249 raeburn 7198: $add_domtitle = &mt('Users in other domain:');
1.241 raeburn 7199: }
7200: $output .= &Apache::loncommon::start_data_table_row()
7201: .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
7202: .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
1.406.2.6 raeburn 7203: $includeempty,$showdomdesc,'','','',$readonly)
1.241 raeburn 7204: .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
7205: .'</td>'.&Apache::loncommon::end_data_table_row()
7206: .&Apache::loncommon::end_data_table();
1.237 raeburn 7207: } elsif ($item eq 'registered') {
7208: my ($regon,$regoff);
1.398 raeburn 7209: my $registered;
7210: if (ref($currsettings) eq 'HASH') {
7211: $registered = $currsettings->{'selfenroll_registered'};
7212: }
1.400 raeburn 7213: if ($noedit{$item}) {
7214: if ($registered) {
7215: $output .= &mt('Must be registered in course');
7216: } else {
7217: $output .= &mt('No requirement');
7218: }
7219: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7220: next;
7221: }
1.398 raeburn 7222: if ($registered) {
1.237 raeburn 7223: $regon = ' checked="checked" ';
1.406.2.6 raeburn 7224: $regoff = '';
1.237 raeburn 7225: } else {
1.406.2.6 raeburn 7226: $regon = '';
1.237 raeburn 7227: $regoff = ' checked="checked" ';
7228: }
7229: $output .= '<label>'.
1.406.2.6 raeburn 7230: '<input type="radio" name="selfenroll_registered" value="1"'.$regon.$disabled.' />'.
1.244 bisitz 7231: &mt('Yes').'</label> <label>'.
1.406.2.6 raeburn 7232: '<input type="radio" name="selfenroll_registered" value="0"'.$regoff.$disabled.' />'.
1.244 bisitz 7233: &mt('No').'</label>';
1.237 raeburn 7234: } elsif ($item eq 'enroll_dates') {
1.398 raeburn 7235: my ($starttime,$endtime);
7236: if (ref($currsettings) eq 'HASH') {
7237: $starttime = $currsettings->{'selfenroll_start_date'};
7238: $endtime = $currsettings->{'selfenroll_end_date'};
7239: if ($starttime eq '') {
7240: $starttime = $currsettings->{'default_enrollment_start_date'};
7241: }
7242: if ($endtime eq '') {
7243: $endtime = $currsettings->{'default_enrollment_end_date'};
7244: }
1.237 raeburn 7245: }
1.400 raeburn 7246: if ($noedit{$item}) {
7247: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7248: &Apache::lonlocal::locallocaltime($endtime));
7249: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7250: next;
7251: }
1.237 raeburn 7252: my $startform =
7253: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_date',$starttime,
1.406.2.6 raeburn 7254: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7255: my $endform =
7256: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_date',$endtime,
1.406.2.6 raeburn 7257: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7258: $output .= &selfenroll_date_forms($startform,$endform);
7259: } elsif ($item eq 'access_dates') {
1.398 raeburn 7260: my ($starttime,$endtime);
7261: if (ref($currsettings) eq 'HASH') {
7262: $starttime = $currsettings->{'selfenroll_start_access'};
7263: $endtime = $currsettings->{'selfenroll_end_access'};
7264: if ($starttime eq '') {
7265: $starttime = $currsettings->{'default_enrollment_start_date'};
7266: }
7267: if ($endtime eq '') {
7268: $endtime = $currsettings->{'default_enrollment_end_date'};
7269: }
1.237 raeburn 7270: }
1.400 raeburn 7271: if ($noedit{$item}) {
7272: $output .= &mt('From: [_1], to: [_2]',&Apache::lonlocal::locallocaltime($starttime),
7273: &Apache::lonlocal::locallocaltime($endtime));
7274: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7275: next;
7276: }
1.237 raeburn 7277: my $startform =
7278: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_start_access',$starttime,
1.406.2.6 raeburn 7279: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7280: my $endform =
7281: &Apache::lonhtmlcommon::date_setter($formname,'selfenroll_end_access',$endtime,
1.406.2.6 raeburn 7282: $disabled,undef,undef,undef,undef,undef,undef,$nolink);
1.237 raeburn 7283: $output .= &selfenroll_date_forms($startform,$endform);
7284: } elsif ($item eq 'section') {
1.398 raeburn 7285: my $currsec;
7286: if (ref($currsettings) eq 'HASH') {
7287: $currsec = $currsettings->{'selfenroll_section'};
7288: }
1.237 raeburn 7289: my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
7290: my $newsecval;
7291: if ($currsec ne 'none' && $currsec ne '') {
7292: if (!defined($sections_count{$currsec})) {
7293: $newsecval = $currsec;
7294: }
7295: }
1.400 raeburn 7296: if ($noedit{$item}) {
7297: if ($currsec ne '') {
7298: $output .= $currsec;
7299: } else {
7300: $output .= &mt('No specific section');
7301: }
7302: $output .= '<br />'.&mt('(Set by Domain Coordinator)');
7303: next;
7304: }
1.237 raeburn 7305: my $sections_select =
1.406.2.6 raeburn 7306: &Apache::lonuserutils::course_sections(\%sections_count,'st',$currsec,$disabled);
1.237 raeburn 7307: $output .= '<table class="LC_createuser">'."\n".
7308: '<tr class="LC_section_row">'."\n".
7309: '<td align="center">'.&mt('Existing sections')."\n".
7310: '<br />'.$sections_select.'</td><td align="center">'.
7311: &mt('New section').'<br />'."\n".
1.406.2.6 raeburn 7312: '<input type="text" name="newsec" size="15" value="'.$newsecval.'"'.$disabled.' />'."\n".
1.237 raeburn 7313: '<input type="hidden" name="sections" value="" />'."\n".
7314: '</td></tr></table>'."\n";
1.276 raeburn 7315: } elsif ($item eq 'approval') {
1.398 raeburn 7316: my ($currnotified,$currapproval,%appchecked);
7317: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.406.2.6 raeburn 7318: if (ref($currsettings) eq 'HASH') {
1.398 raeburn 7319: $currnotified = $currsettings->{'selfenroll_notifylist'};
7320: $currapproval = $currsettings->{'selfenroll_approval'};
7321: }
7322: if ($currapproval !~ /^[012]$/) {
7323: $currapproval = 0;
7324: }
1.400 raeburn 7325: if ($noedit{$item}) {
7326: $output .= $selfdescs{'approval'}{$currapproval}.
7327: '<br />'.&mt('(Set by Domain Coordinator)');
7328: next;
7329: }
1.398 raeburn 7330: $appchecked{$currapproval} = ' checked="checked"';
7331: for my $i (0..2) {
7332: $output .= '<label>'.
7333: '<input type="radio" name="selfenroll_approval" value="'.$i.'"'.
1.406.2.6 raeburn 7334: $appchecked{$i}.' onclick="toggleNotify();"'.$disabled.' />'.
7335: $selfdescs{'approval'}{$i}.'</label>'.(' 'x2);
1.276 raeburn 7336: }
7337: my %advhash = &Apache::lonnet::get_course_adv_roles($cid,1);
7338: my (@ccs,%notified);
1.322 raeburn 7339: my $ccrole = 'cc';
7340: if ($crstype eq 'Community') {
7341: $ccrole = 'co';
7342: }
7343: if ($advhash{$ccrole}) {
7344: @ccs = split(/,/,$advhash{$ccrole});
1.276 raeburn 7345: }
7346: if ($currnotified) {
7347: foreach my $current (split(/,/,$currnotified)) {
7348: $notified{$current} = 1;
7349: if (!grep(/^\Q$current\E$/,@ccs)) {
7350: push(@ccs,$current);
7351: }
7352: }
7353: }
7354: if (@ccs) {
1.398 raeburn 7355: my $style;
7356: unless ($currapproval) {
7357: $style = ' style="display: none;"';
7358: }
7359: $output .= '<br /><div id="notified"'.$style.'>'.
7360: &mt('Personnel to be notified when an enrollment request needs approval, or has been approved:').' '.
7361: &Apache::loncommon::start_data_table().
1.276 raeburn 7362: &Apache::loncommon::start_data_table_row();
7363: my $count = 0;
7364: my $numcols = 4;
7365: foreach my $cc (sort(@ccs)) {
7366: my $notifyon;
7367: my ($ccuname,$ccudom) = split(/:/,$cc);
7368: if ($notified{$cc}) {
7369: $notifyon = ' checked="checked" ';
7370: }
7371: if ($count && !$count%$numcols) {
7372: $output .= &Apache::loncommon::end_data_table_row().
7373: &Apache::loncommon::start_data_table_row()
7374: }
7375: $output .= '<td><span class="LC_nobreak"><label>'.
1.406.2.6 raeburn 7376: '<input type="checkbox" name="selfenroll_notify"'.$notifyon.' value="'.$cc.'"'.$disabled.' />'.
1.276 raeburn 7377: &Apache::loncommon::plainname($ccuname,$ccudom).
7378: '</label></span></td>';
1.343 raeburn 7379: $count ++;
1.276 raeburn 7380: }
7381: my $rem = $count%$numcols;
7382: if ($rem) {
7383: my $emptycols = $numcols - $rem;
7384: for (my $i=0; $i<$emptycols; $i++) {
7385: $output .= '<td> </td>';
7386: }
7387: }
7388: $output .= &Apache::loncommon::end_data_table_row().
1.398 raeburn 7389: &Apache::loncommon::end_data_table().
7390: '</div>';
1.276 raeburn 7391: }
7392: } elsif ($item eq 'limit') {
1.398 raeburn 7393: my ($crslimit,$selflimit,$nolimit,$currlim,$currcap);
7394: if (ref($currsettings) eq 'HASH') {
7395: $currlim = $currsettings->{'selfenroll_limit'};
7396: $currcap = $currsettings->{'selfenroll_cap'};
7397: }
1.400 raeburn 7398: if ($noedit{$item}) {
7399: if (($currlim eq 'allstudents') || ($currlim eq 'selfenrolled')) {
7400: if ($currlim eq 'allstudents') {
7401: $output .= &mt('Limit by total students');
7402: } elsif ($currlim eq 'selfenrolled') {
7403: $output .= &mt('Limit by total self-enrolled students');
7404: }
7405: $output .= ' '.&mt('Maximum: [_1]',$currcap).
7406: '<br />'.&mt('(Set by Domain Coordinator)');
7407: } else {
7408: $output .= &mt('No limit').'<br />'.&mt('(Set by Domain Coordinator)');
7409: }
7410: next;
7411: }
1.276 raeburn 7412: if ($currlim eq 'allstudents') {
7413: $crslimit = ' checked="checked" ';
7414: $selflimit = ' ';
7415: $nolimit = ' ';
7416: } elsif ($currlim eq 'selfenrolled') {
7417: $crslimit = ' ';
7418: $selflimit = ' checked="checked" ';
7419: $nolimit = ' ';
7420: } else {
7421: $crslimit = ' ';
7422: $selflimit = ' ';
1.398 raeburn 7423: $nolimit = ' checked="checked" ';
1.276 raeburn 7424: }
7425: $output .= '<table><tr><td><label>'.
1.406.2.6 raeburn 7426: '<input type="radio" name="selfenroll_limit" value="none"'.$nolimit.$disabled.'/>'.
1.276 raeburn 7427: &mt('No limit').'</label></td><td><label>'.
1.406.2.6 raeburn 7428: '<input type="radio" name="selfenroll_limit" value="allstudents"'.$crslimit.$disabled.'/>'.
1.276 raeburn 7429: &mt('Limit by total students').'</label></td><td><label>'.
1.406.2.6 raeburn 7430: '<input type="radio" name="selfenroll_limit" value="selfenrolled"'.$selflimit.$disabled.'/>'.
1.276 raeburn 7431: &mt('Limit by total self-enrolled students').
7432: '</td></tr><tr>'.
7433: '<td> </td><td colspan="2"><span class="LC_nobreak">'.
7434: (' 'x3).&mt('Maximum number allowed: ').
1.406.2.6 raeburn 7435: '<input type="text" name="selfenroll_cap" size = "5" value="'.$currcap.'"'.$disabled.' /></td></tr></table>';
1.237 raeburn 7436: }
7437: $output .= &Apache::lonhtmlcommon::row_closure(1);
7438: }
7439: }
1.406.2.6 raeburn 7440: $output .= &Apache::lonhtmlcommon::end_pick_box().'<br />';
7441: unless ($readonly) {
7442: $output .= '<input type="button" name="selfenrollconf" value="'
7443: .&mt('Save').'" onclick="validate_types(this.form);" />';
7444: }
7445: $output .= '<input type="hidden" name="action" value="selfenroll" />'
1.406.2.11 raeburn 7446: .'<input type="hidden" name="state" value="done" />'."\n"
7447: .$additional.'</form>';
1.237 raeburn 7448: $r->print($output);
7449: return;
7450: }
7451:
1.400 raeburn 7452: sub get_noedit_fields {
7453: my ($cdom,$cnum,$crstype,$row) = @_;
7454: my %noedit;
7455: if (ref($row) eq 'ARRAY') {
7456: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
7457: 'internal.selfenrollmgrdc',
7458: 'internal.selfenrollmgrcc'],$cdom,$cnum);
7459: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
7460: my (%specific_managebydc,%specific_managebycc,%default_managebydc);
7461: map { $specific_managebydc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrdc'}));
7462: map { $specific_managebycc{$_} = 1; } (split(/,/,$settings{'internal.selfenrollmgrcc'}));
7463: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
7464: map { $default_managebydc{$_} = 1; } (split(/,/,$domdefaults{$type.'selfenrolladmdc'}));
7465:
7466: foreach my $item (@{$row}) {
7467: next if ($specific_managebycc{$item});
7468: if (($specific_managebydc{$item}) || ($default_managebydc{$item})) {
7469: $noedit{$item} = 1;
7470: }
7471: }
7472: }
7473: return %noedit;
7474: }
7475:
7476: sub visible_in_stdcat {
7477: my ($cdom,$cnum,$domconf) = @_;
7478: my ($cathash,%settable,@vismsgs,$cansetvis,$visible);
7479: unless (ref($domconf) eq 'HASH') {
7480: return ($visible,$cansetvis,\@vismsgs);
7481: }
7482: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7483: if ($domconf->{'coursecategories'}{'togglecats'} eq 'crs') {
1.256 raeburn 7484: $settable{'togglecats'} = 1;
7485: }
1.400 raeburn 7486: if ($domconf->{'coursecategories'}{'categorize'} eq 'crs') {
1.256 raeburn 7487: $settable{'categorize'} = 1;
7488: }
1.400 raeburn 7489: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7490: }
1.260 raeburn 7491: if ($settable{'togglecats'} && $settable{'categorize'}) {
1.256 raeburn 7492: $cansetvis = &mt('You are able to both assign a course category and choose to exclude this course from the catalog.');
7493: } elsif ($settable{'togglecats'}) {
7494: $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 7495: } elsif ($settable{'categorize'}) {
1.256 raeburn 7496: $cansetvis = &mt('You may assign a course category, but only a Domain Coordinator may choose to exclude this course from the catalog.');
7497: } else {
7498: $cansetvis = &mt('Only a Domain Coordinator may assign a course category or choose to exclude this course from the catalog.');
7499: }
7500:
7501: my %currsettings =
7502: &Apache::lonnet::get('environment',['hidefromcat','categories','internal.coursecode'],
7503: $cdom,$cnum);
1.400 raeburn 7504: $visible = 0;
1.256 raeburn 7505: if ($currsettings{'internal.coursecode'} ne '') {
1.400 raeburn 7506: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7507: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7508: if (ref($cathash) eq 'HASH') {
7509: if ($cathash->{'instcode::0'} eq '') {
7510: push(@vismsgs,'dc_addinst');
7511: } else {
7512: $visible = 1;
7513: }
7514: } else {
7515: $visible = 1;
7516: }
7517: } else {
7518: $visible = 1;
7519: }
7520: } else {
7521: if (ref($cathash) eq 'HASH') {
7522: if ($cathash->{'instcode::0'} ne '') {
7523: push(@vismsgs,'dc_instcode');
7524: }
7525: } else {
7526: push(@vismsgs,'dc_instcode');
7527: }
7528: }
7529: if ($currsettings{'categories'} ne '') {
7530: my $cathash;
1.400 raeburn 7531: if (ref($domconf->{'coursecategories'}) eq 'HASH') {
7532: $cathash = $domconf->{'coursecategories'}{'cats'};
1.256 raeburn 7533: if (ref($cathash) eq 'HASH') {
7534: if (keys(%{$cathash}) == 0) {
7535: push(@vismsgs,'dc_catalog');
7536: } elsif ((keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} ne '')) {
7537: push(@vismsgs,'dc_categories');
7538: } else {
7539: my @currcategories = split('&',$currsettings{'categories'});
7540: my $matched = 0;
7541: foreach my $cat (@currcategories) {
7542: if ($cathash->{$cat} ne '') {
7543: $visible = 1;
7544: $matched = 1;
7545: last;
7546: }
7547: }
7548: if (!$matched) {
1.260 raeburn 7549: if ($settable{'categorize'}) {
1.256 raeburn 7550: push(@vismsgs,'chgcat');
7551: } else {
7552: push(@vismsgs,'dc_chgcat');
7553: }
7554: }
7555: }
7556: }
7557: }
7558: } else {
7559: if (ref($cathash) eq 'HASH') {
7560: if ((keys(%{$cathash}) > 1) ||
7561: (keys(%{$cathash}) == 1) && ($cathash->{'instcode::0'} eq '')) {
1.260 raeburn 7562: if ($settable{'categorize'}) {
1.256 raeburn 7563: push(@vismsgs,'addcat');
7564: } else {
7565: push(@vismsgs,'dc_addcat');
7566: }
7567: }
7568: }
7569: }
7570: if ($currsettings{'hidefromcat'} eq 'yes') {
7571: $visible = 0;
7572: if ($settable{'togglecats'}) {
7573: unshift(@vismsgs,'unhide');
7574: } else {
7575: unshift(@vismsgs,'dc_unhide')
7576: }
7577: }
1.400 raeburn 7578: return ($visible,$cansetvis,\@vismsgs);
7579: }
7580:
7581: sub cat_visibility {
1.406.2.20.2. (raeburn 7582:): my ($cdom) = @_;
1.400 raeburn 7583: my %visactions = &Apache::lonlocal::texthash(
7584: vis => 'This course/community currently appears in the Course/Community Catalog for this domain.',
7585: 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.',
7586: miss => 'This course/community does not currently appear in the Course/Community Catalog for this domain.',
7587: none => 'Display of a course catalog is disabled for this domain.',
7588: yous => 'You should remedy this if you plan to allow self-enrollment, otherwise students will have difficulty finding this course.',
7589: 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.',
7590: make => 'Make any changes to self-enrollment settings below, click "Save", then take action to include the course in the Catalog:',
7591: take => 'Take the following action to ensure the course appears in the Catalog:',
7592: dc_chgconf => 'Ask a domain coordinator to change the Catalog type for this domain.',
7593: dc_setcode => 'Ask a domain coordinator to assign a six character code to the course',
7594: dc_unhide => 'Ask a domain coordinator to change the "Exclude from course catalog" setting.',
1.406.2.20.2. (raeburn 7595:): dc_addinst => 'Ask a domain coordinator to enable catalog display of "Official courses (with institutional codes)".',
1.400 raeburn 7596: dc_instcode => 'Ask a domain coordinator to assign an institutional code (if this is an official course).',
7597: dc_catalog => 'Ask a domain coordinator to enable or create at least one course category in the domain.',
7598: dc_categories => 'Ask a domain coordinator to create a hierarchy of categories and sub categories for courses in the domain.',
7599: 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',
7600: dc_addcat => 'Ask a domain coordinator to assign a category to the course.',
7601: );
1.406.2.20.2. (raeburn 7602:): if ($env{'request.role'} eq "dc./$cdom/") {
7603:): $visactions{'dc_chgconf'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the Catalog type for this domain.','»');
7604:): $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.','»');
7605:): $visactions{'dc_unhide'} = &mt('Use: "Main menu" [_1] "Set domain configuration" [_1] "Cataloging of courses/communities" to change the "Exclude from course catalog" setting.','»');
7606:): $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)".','»');
7607:): $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).','»');
7608:): $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.','»');
7609:): $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.','»');
7610:): $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.','»');
7611:): $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.','»');
7612:): }
1.400 raeburn 7613: $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>"');
7614: $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>"');
7615: $visactions{'addcat'} = &mt('Use [_1]Categorize course[_2] to assign a category to the course.','"<a href="/adm/courseprefs?phase=display&actions=courseinfo">','</a>"');
7616: return \%visactions;
1.256 raeburn 7617: }
7618:
1.241 raeburn 7619: sub new_selfenroll_dom_row {
7620: my ($newdom,$num) = @_;
7621: my $domdesc = &Apache::lonnet::domain($newdom);
7622: my $output;
7623: if ($domdesc ne '') {
7624: $output .= &Apache::loncommon::start_data_table_row()
7625: .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').' <b>'.$domdesc
7626: .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
1.249 raeburn 7627: .'" value="'.$newdom.'" /></span><br />'
7628: .'<span class="LC_nobreak"><label><input type="checkbox" '
7629: .'name="selfenroll_activate" value="'.$num.'" '
7630: .'onchange="javascript:update_types('
7631: ."'selfenroll_activate','$num'".');" />'
7632: .&mt('Activate').'</label></span></td>';
1.241 raeburn 7633: my @currinsttypes;
7634: $output .= '<td>'.&mt('User types:').'<br />'
7635: .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
7636: .&Apache::loncommon::end_data_table_row();
7637: }
7638: return $output;
7639: }
7640:
7641: sub selfenroll_inst_types {
1.406.2.6 raeburn 7642: my ($num,$currdom,$currinsttypes,$readonly) = @_;
1.241 raeburn 7643: my $output;
7644: my $numinrow = 4;
7645: my $count = 0;
7646: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
1.247 raeburn 7647: my $othervalue = 'any';
1.406.2.6 raeburn 7648: my $disabled;
7649: if ($readonly) {
7650: $disabled = ' disabled="disabled"';
7651: }
1.241 raeburn 7652: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
1.251 raeburn 7653: if (keys(%{$usertypes}) > 0) {
1.247 raeburn 7654: $othervalue = 'other';
7655: }
1.241 raeburn 7656: $output .= '<table><tr>';
7657: foreach my $type (@{$types}) {
7658: if (($count > 0) && ($count%$numinrow == 0)) {
7659: $output .= '</tr><tr>';
7660: }
7661: if (defined($usertypes->{$type})) {
1.257 raeburn 7662: my $esc_type = &escape($type);
1.241 raeburn 7663: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
1.257 raeburn 7664: $esc_type.'" ';
1.241 raeburn 7665: if (ref($currinsttypes) eq 'ARRAY') {
7666: if (@{$currinsttypes} > 0) {
1.249 raeburn 7667: if (grep(/^any$/,@{$currinsttypes})) {
7668: $output .= 'checked="checked"';
1.257 raeburn 7669: } elsif (grep(/^\Q$esc_type\E$/,@{$currinsttypes})) {
1.241 raeburn 7670: $output .= 'checked="checked"';
7671: }
1.249 raeburn 7672: } else {
7673: $output .= 'checked="checked"';
1.241 raeburn 7674: }
7675: }
1.406.2.6 raeburn 7676: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$usertypes->{$type}.'</label></span></td>';
1.241 raeburn 7677: }
7678: $count ++;
7679: }
7680: if (($count > 0) && ($count%$numinrow == 0)) {
7681: $output .= '</tr><tr>';
7682: }
1.249 raeburn 7683: $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.$othervalue.'"';
1.241 raeburn 7684: if (ref($currinsttypes) eq 'ARRAY') {
7685: if (@{$currinsttypes} > 0) {
1.249 raeburn 7686: if (grep(/^any$/,@{$currinsttypes})) {
7687: $output .= ' checked="checked"';
7688: } elsif ($othervalue eq 'other') {
7689: if (grep(/^\Q$othervalue\E$/,@{$currinsttypes})) {
7690: $output .= ' checked="checked"';
7691: }
1.241 raeburn 7692: }
1.249 raeburn 7693: } else {
7694: $output .= ' checked="checked"';
1.241 raeburn 7695: }
1.249 raeburn 7696: } else {
7697: $output .= ' checked="checked"';
1.241 raeburn 7698: }
1.406.2.6 raeburn 7699: $output .= ' name="selfenroll_types_'.$num.'"'.$disabled.' />'.$othertitle.'</label></span></td></tr></table>';
1.241 raeburn 7700: }
7701: return $output;
7702: }
7703:
1.237 raeburn 7704: sub selfenroll_date_forms {
7705: my ($startform,$endform) = @_;
7706: my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
1.244 bisitz 7707: &Apache::lonhtmlcommon::row_title(&mt('Start date'),
1.237 raeburn 7708: 'LC_oddrow_value')."\n".
7709: $startform."\n".
7710: &Apache::lonhtmlcommon::row_closure(1).
1.244 bisitz 7711: &Apache::lonhtmlcommon::row_title(&mt('End date'),
1.237 raeburn 7712: 'LC_oddrow_value')."\n".
7713: $endform."\n".
7714: &Apache::lonhtmlcommon::row_closure(1).
7715: &Apache::lonhtmlcommon::end_pick_box();
7716: return $output;
7717: }
7718:
1.239 raeburn 7719: sub print_userchangelogs_display {
1.406.2.5 raeburn 7720: my ($r,$context,$permission,$brcrum) = @_;
1.363 raeburn 7721: my $formname = 'rolelog';
1.406.2.6 raeburn 7722: my ($username,$domain,$crstype,$viewablesec,%roleslog);
1.363 raeburn 7723: if ($context eq 'domain') {
7724: $domain = $env{'request.role.domain'};
7725: %roleslog=&Apache::lonnet::dump_dom('nohist_rolelog',$domain);
7726: } else {
7727: if ($context eq 'course') {
7728: $domain = $env{'course.'.$env{'request.course.id'}.'.domain'};
7729: $username = $env{'course.'.$env{'request.course.id'}.'.num'};
7730: $crstype = &Apache::loncommon::course_type();
1.406.2.6 raeburn 7731: $viewablesec = &Apache::lonuserutils::viewable_section($permission);
1.363 raeburn 7732: my %saveable_parameters = ('show' => 'scalar',);
7733: &Apache::loncommon::store_course_settings('roles_log',
7734: \%saveable_parameters);
7735: &Apache::loncommon::restore_course_settings('roles_log',
7736: \%saveable_parameters);
7737: } elsif ($context eq 'author') {
1.406.2.20.2. (raeburn 7738:): $domain = $env{'user.domain'};
1.363 raeburn 7739: if ($env{'request.role'} =~ m{^au\./\Q$domain\E/$}) {
7740: $username = $env{'user.name'};
1.406.2.20.2. (raeburn 7741:): } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)$}) {
7742:): ($domain,$username) = ($1,$2);
1.363 raeburn 7743: } else {
7744: undef($domain);
7745: }
7746: }
7747: if ($domain ne '' && $username ne '') {
7748: %roleslog=&Apache::lonnet::dump('nohist_rolelog',$domain,$username);
7749: }
7750: }
1.239 raeburn 7751: if ((keys(%roleslog))[0]=~/^error\:/) { undef(%roleslog); }
7752:
1.406.2.5 raeburn 7753: my $helpitem;
7754: if ($context eq 'course') {
7755: $helpitem = 'Course_User_Logs';
1.406.2.14 raeburn 7756: } elsif ($context eq 'domain') {
7757: $helpitem = 'Domain_Role_Logs';
7758: } elsif ($context eq 'author') {
7759: $helpitem = 'Author_User_Logs';
1.406.2.5 raeburn 7760: }
7761: push (@{$brcrum},
7762: {href => '/adm/createuser?action=changelogs',
7763: text => 'User Management Logs',
7764: help => $helpitem});
7765: my $bread_crumbs_component = 'User Changes';
7766: my $args = { bread_crumbs => $brcrum,
7767: bread_crumbs_component => $bread_crumbs_component};
7768:
7769: # Create navigation javascript
7770: my $jsnav = &userlogdisplay_js($formname);
7771:
7772: my $jscript = (<<ENDSCRIPT);
7773: <script type="text/javascript">
7774: // <![CDATA[
7775: $jsnav
7776: // ]]>
7777: </script>
7778: ENDSCRIPT
7779:
7780: # print page header
7781: $r->print(&header($jscript,$args));
7782:
1.239 raeburn 7783: # set defaults
7784: my $now = time();
7785: my $defstart = $now - (7*24*3600); #7 days ago
7786: my %defaults = (
7787: page => '1',
7788: show => '10',
7789: role => 'any',
7790: chgcontext => 'any',
7791: rolelog_start_date => $defstart,
7792: rolelog_end_date => $now,
7793: );
7794: my $more_records = 0;
7795:
7796: # set current
7797: my %curr;
7798: foreach my $item ('show','page','role','chgcontext') {
7799: $curr{$item} = $env{'form.'.$item};
7800: }
7801: my ($startdate,$enddate) =
7802: &Apache::lonuserutils::get_dates_from_form('rolelog_start_date','rolelog_end_date');
7803: $curr{'rolelog_start_date'} = $startdate;
7804: $curr{'rolelog_end_date'} = $enddate;
7805: foreach my $key (keys(%defaults)) {
7806: if ($curr{$key} eq '') {
7807: $curr{$key} = $defaults{$key};
7808: }
7809: }
1.248 raeburn 7810: my (%whodunit,%changed,$version);
7811: ($version) = ($r->dir_config('lonVersion') =~ /^([\d\.]+)\-/);
1.239 raeburn 7812: my ($minshown,$maxshown);
1.255 raeburn 7813: $minshown = 1;
1.239 raeburn 7814: my $count = 0;
1.406.2.5 raeburn 7815: if ($curr{'show'} =~ /\D/) {
7816: $curr{'page'} = 1;
7817: } else {
1.239 raeburn 7818: $maxshown = $curr{'page'} * $curr{'show'};
7819: if ($curr{'page'} > 1) {
7820: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
7821: }
7822: }
1.301 bisitz 7823:
1.327 raeburn 7824: # Form Header
7825: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
1.363 raeburn 7826: &role_display_filter($context,$formname,$domain,$username,\%curr,
7827: $version,$crstype));
1.327 raeburn 7828:
7829: my $showntableheader = 0;
7830:
7831: # Table Header
7832: my $tableheader =
7833: &Apache::loncommon::start_data_table_header_row()
7834: .'<th> </th>'
7835: .'<th>'.&mt('When').'</th>'
7836: .'<th>'.&mt('Who made the change').'</th>'
7837: .'<th>'.&mt('Changed User').'</th>'
1.363 raeburn 7838: .'<th>'.&mt('Role').'</th>';
7839:
7840: if ($context eq 'course') {
7841: $tableheader .= '<th>'.&mt('Section').'</th>';
7842: }
7843: $tableheader .=
7844: '<th>'.&mt('Context').'</th>'
1.327 raeburn 7845: .'<th>'.&mt('Start').'</th>'
7846: .'<th>'.&mt('End').'</th>'
7847: .&Apache::loncommon::end_data_table_header_row();
7848:
7849: # Display user change log data
1.239 raeburn 7850: foreach my $id (sort { $roleslog{$b}{'exe_time'}<=>$roleslog{$a}{'exe_time'} } (keys(%roleslog))) {
7851: next if (($roleslog{$id}{'exe_time'} < $curr{'rolelog_start_date'}) ||
7852: ($roleslog{$id}{'exe_time'} > $curr{'rolelog_end_date'}));
1.406.2.5 raeburn 7853: if ($curr{'show'} !~ /\D/) {
1.239 raeburn 7854: if ($count >= $curr{'page'} * $curr{'show'}) {
7855: $more_records = 1;
7856: last;
7857: }
7858: }
7859: if ($curr{'role'} ne 'any') {
7860: next if ($roleslog{$id}{'logentry'}{'role'} ne $curr{'role'});
7861: }
7862: if ($curr{'chgcontext'} ne 'any') {
7863: if ($curr{'chgcontext'} eq 'selfenroll') {
7864: next if (!$roleslog{$id}{'logentry'}{'selfenroll'});
7865: } else {
7866: next if ($roleslog{$id}{'logentry'}{'context'} ne $curr{'chgcontext'});
7867: }
7868: }
1.406.2.6 raeburn 7869: if (($context eq 'course') && ($viewablesec ne '')) {
7870: next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
7871: }
1.239 raeburn 7872: $count ++;
7873: next if ($count < $minshown);
1.327 raeburn 7874: unless ($showntableheader) {
1.406.2.5 raeburn 7875: $r->print(&Apache::loncommon::start_data_table()
1.327 raeburn 7876: .$tableheader);
7877: $r->rflush();
7878: $showntableheader = 1;
7879: }
1.239 raeburn 7880: if ($whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} eq '') {
7881: $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}} =
7882: &Apache::loncommon::plainname($roleslog{$id}{'exe_uname'},$roleslog{$id}{'exe_udom'});
7883: }
7884: if ($changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} eq '') {
7885: $changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}} =
7886: &Apache::loncommon::plainname($roleslog{$id}{'uname'},$roleslog{$id}{'udom'});
7887: }
7888: my $sec = $roleslog{$id}{'logentry'}{'section'};
7889: if ($sec eq '') {
7890: $sec = &mt('None');
7891: }
7892: my ($rolestart,$roleend);
7893: if ($roleslog{$id}{'delflag'}) {
7894: $rolestart = &mt('deleted');
7895: $roleend = &mt('deleted');
7896: } else {
7897: $rolestart = $roleslog{$id}{'logentry'}{'start'};
7898: $roleend = $roleslog{$id}{'logentry'}{'end'};
7899: if ($rolestart eq '' || $rolestart == 0) {
7900: $rolestart = &mt('No start date');
7901: } else {
7902: $rolestart = &Apache::lonlocal::locallocaltime($rolestart);
7903: }
7904: if ($roleend eq '' || $roleend == 0) {
7905: $roleend = &mt('No end date');
7906: } else {
7907: $roleend = &Apache::lonlocal::locallocaltime($roleend);
7908: }
7909: }
7910: my $chgcontext = $roleslog{$id}{'logentry'}{'context'};
7911: if ($roleslog{$id}{'logentry'}{'selfenroll'}) {
7912: $chgcontext = 'selfenroll';
7913: }
1.363 raeburn 7914: my %lt = &rolechg_contexts($context,$crstype);
1.239 raeburn 7915: if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
7916: $chgcontext = $lt{$chgcontext};
7917: }
1.327 raeburn 7918: $r->print(
1.301 bisitz 7919: &Apache::loncommon::start_data_table_row()
7920: .'<td>'.$count.'</td>'
7921: .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
7922: .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
7923: .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
1.363 raeburn 7924: .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
7925: if ($context eq 'course') {
7926: $r->print('<td>'.$sec.'</td>');
7927: }
7928: $r->print(
7929: '<td>'.$chgcontext.'</td>'
1.301 bisitz 7930: .'<td>'.$rolestart.'</td>'
7931: .'<td>'.$roleend.'</td>'
1.327 raeburn 7932: .&Apache::loncommon::end_data_table_row()."\n");
1.301 bisitz 7933: }
7934:
1.327 raeburn 7935: if ($showntableheader) { # Table footer, if content displayed above
1.406.2.5 raeburn 7936: $r->print(&Apache::loncommon::end_data_table().
7937: &userlogdisplay_navlinks(\%curr,$more_records));
1.327 raeburn 7938: } else { # No content displayed above
1.301 bisitz 7939: $r->print('<p class="LC_info">'
7940: .&mt('There are no records to display.')
7941: .'</p>'
7942: );
1.239 raeburn 7943: }
1.301 bisitz 7944:
1.327 raeburn 7945: # Form Footer
7946: $r->print(
7947: '<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
7948: .'<input type="hidden" name="action" value="changelogs" />'
7949: .'</form>');
7950: return;
7951: }
1.301 bisitz 7952:
1.406.2.5 raeburn 7953: sub print_useraccesslogs_display {
7954: my ($r,$uname,$udom,$permission,$brcrum) = @_;
7955: my $formname = 'accesslog';
7956: my $form = 'document.accesslog';
7957:
7958: # set breadcrumbs
1.406.2.7 raeburn 7959: my %breadcrumb_text = &singleuser_breadcrumb('','domain',$udom);
1.406.2.12 raeburn 7960: my $prevphasestr;
7961: if ($env{'form.popup'}) {
7962: $brcrum = [];
7963: } else {
7964: push (@{$brcrum},
7965: {href => "javascript:backPage($form)",
7966: text => $breadcrumb_text{'search'}});
7967: my @prevphases;
7968: if ($env{'form.prevphases'}) {
7969: @prevphases = split(/,/,$env{'form.prevphases'});
7970: $prevphasestr = $env{'form.prevphases'};
7971: }
7972: if (($env{'form.phase'} eq 'userpicked') || (grep(/^userpicked$/,@prevphases))) {
7973: push(@{$brcrum},
7974: {href => "javascript:backPage($form,'get_user_info','select')",
7975: text => $breadcrumb_text{'userpicked'}});
7976: if ($env{'form.phase'} eq 'userpicked') {
7977: $prevphasestr = 'userpicked';
7978: }
1.406.2.5 raeburn 7979: }
7980: }
7981: push(@{$brcrum},
7982: {href => '/adm/createuser?action=accesslogs',
7983: text => 'User access logs',
1.406.2.8 raeburn 7984: help => 'Domain_User_Access_Logs'});
1.406.2.5 raeburn 7985: my $bread_crumbs_component = 'User Access Logs';
7986: my $args = { bread_crumbs => $brcrum,
7987: bread_crumbs_component => 'User Management'};
1.406.2.8 raeburn 7988: if ($env{'form.popup'}) {
7989: $args->{'no_nav_bar'} = 1;
1.406.2.12 raeburn 7990: $args->{'bread_crumbs_nomenu'} = 1;
1.406.2.8 raeburn 7991: }
1.406.2.5 raeburn 7992:
7993: # set javascript
7994: my ($jsback,$elements) = &crumb_utilities();
7995: my $jsnav = &userlogdisplay_js($formname);
7996:
7997: my $jscript = (<<ENDSCRIPT);
1.239 raeburn 7998: <script type="text/javascript">
1.301 bisitz 7999: // <![CDATA[
1.406.2.5 raeburn 8000:
8001: $jsback
8002: $jsnav
8003:
8004: // ]]>
8005: </script>
8006:
8007: ENDSCRIPT
8008:
8009: # print page header
8010: $r->print(&header($jscript,$args));
8011:
8012: # early out unless log data can be displayed.
8013: unless ($permission->{'activity'}) {
8014: $r->print('<p class="LC_warning">'
8015: .&mt('You do not have rights to display user access logs.')
1.406.2.12 raeburn 8016: .'</p>');
8017: if ($env{'form.popup'}) {
8018: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8019: } else {
8020: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8021: }
1.406.2.5 raeburn 8022: return;
8023: }
8024:
8025: unless ($udom eq $env{'request.role.domain'}) {
8026: $r->print('<p class="LC_warning">'
8027: .&mt("User's domain must match role's domain")
8028: .'</p>'
8029: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8030: return;
8031: }
8032:
8033: if (($uname eq '') || ($udom eq '')) {
8034: $r->print('<p class="LC_warning">'
8035: .&mt('Invalid username or domain')
8036: .'</p>'
8037: .&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8038: return;
8039: }
8040:
1.406.2.13 raeburn 8041: if (&Apache::lonnet::privileged($uname,$udom,
8042: [$env{'request.role.domain'}],['dc','su'])) {
8043: unless (&Apache::lonnet::privileged($env{'user.name'},$env{'user.domain'},
8044: [$env{'request.role.domain'}],['dc','su'])) {
8045: $r->print('<p class="LC_warning">'
8046: .&mt('You need to be a privileged user to display user access logs for [_1]',
8047: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),
8048: $uname,$udom))
8049: .'</p>');
8050: if ($env{'form.popup'}) {
8051: $r->print('<p><a href="javascript:window.close()">'.&mt('Close window').'</a></p>');
8052: } else {
8053: $r->print(&earlyout_accesslog_form($formname,$prevphasestr,$udom));
8054: }
8055: return;
8056: }
8057: }
8058:
1.406.2.5 raeburn 8059: # set defaults
8060: my $now = time();
8061: my $defstart = $now - (7*24*3600);
8062: my %defaults = (
8063: page => '1',
8064: show => '10',
8065: activity => 'any',
8066: accesslog_start_date => $defstart,
8067: accesslog_end_date => $now,
8068: );
8069: my $more_records = 0;
8070:
8071: # set current
8072: my %curr;
8073: foreach my $item ('show','page','activity') {
8074: $curr{$item} = $env{'form.'.$item};
8075: }
8076: my ($startdate,$enddate) =
8077: &Apache::lonuserutils::get_dates_from_form('accesslog_start_date','accesslog_end_date');
8078: $curr{'accesslog_start_date'} = $startdate;
8079: $curr{'accesslog_end_date'} = $enddate;
8080: foreach my $key (keys(%defaults)) {
8081: if ($curr{$key} eq '') {
8082: $curr{$key} = $defaults{$key};
8083: }
8084: }
8085: my ($minshown,$maxshown);
8086: $minshown = 1;
8087: my $count = 0;
8088: if ($curr{'show'} =~ /\D/) {
8089: $curr{'page'} = 1;
8090: } else {
8091: $maxshown = $curr{'page'} * $curr{'show'};
8092: if ($curr{'page'} > 1) {
8093: $minshown = 1 + ($curr{'page'} - 1) * $curr{'show'};
8094: }
8095: }
8096:
8097: # form header
8098: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">'.
8099: &activity_display_filter($formname,\%curr));
8100:
8101: my $showntableheader = 0;
8102: my ($nav_script,$nav_links);
8103:
8104: # table header
1.406.2.18 raeburn 8105: my $heading = '<h3>'.
1.406.2.12 raeburn 8106: &mt('User access logs for: [_1]',
1.406.2.18 raeburn 8107: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom)).'</h3>';
8108: my $tableheader = $heading
1.406.2.12 raeburn 8109: .&Apache::loncommon::start_data_table_header_row()
1.406.2.5 raeburn 8110: .'<th> </th>'
8111: .'<th>'.&mt('When').'</th>'
8112: .'<th>'.&mt('HostID').'</th>'
8113: .'<th>'.&mt('Event').'</th>'
8114: .'<th>'.&mt('Other data').'</th>'
8115: .&Apache::loncommon::end_data_table_header_row();
8116:
8117: my %filters=(
8118: start => $curr{'accesslog_start_date'},
8119: end => $curr{'accesslog_end_date'},
8120: action => $curr{'activity'},
8121: );
8122:
8123: my $reply = &Apache::lonnet::userlog_query($uname,$udom,%filters);
8124: unless ( ($reply =~/^timeout/) || ($reply =~/^error/) ) {
8125: my (%courses,%missing);
8126: my @results = split(/\&/,$reply);
8127: foreach my $item (reverse(@results)) {
8128: my ($timestamp,$host,$event) = split(/:/,$item);
8129: next unless ($event =~ /^(Log|Role)/);
8130: if ($curr{'show'} !~ /\D/) {
8131: if ($count >= $curr{'page'} * $curr{'show'}) {
8132: $more_records = 1;
8133: last;
8134: }
8135: }
8136: $count ++;
8137: next if ($count < $minshown);
8138: unless ($showntableheader) {
8139: $r->print($nav_script
8140: .&Apache::loncommon::start_data_table()
8141: .$tableheader);
8142: $r->rflush();
8143: $showntableheader = 1;
8144: }
1.406.2.6 raeburn 8145: my ($shown,$extra);
1.406.2.13 raeburn 8146: my ($event,$data) = split(/\s+/,&unescape($event),2);
1.406.2.5 raeburn 8147: if ($event eq 'Role') {
8148: my ($rolecode,$extent) = split(/\./,$data,2);
8149: next if ($extent eq '');
8150: my ($crstype,$desc,$info);
1.406.2.6 raeburn 8151: if ($extent =~ m{^/($match_domain)/($match_courseid)(?:/(\w+)|)$}) {
8152: my ($cdom,$cnum,$sec) = ($1,$2,$3);
1.406.2.5 raeburn 8153: my $cid = $cdom.'_'.$cnum;
8154: if (exists($courses{$cid})) {
8155: $crstype = $courses{$cid}{'type'};
8156: $desc = $courses{$cid}{'description'};
8157: } elsif ($missing{$cid}) {
8158: $crstype = 'Course';
8159: $desc = 'Course/Community';
8160: } else {
8161: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,undef,undef,'.');
8162: if (ref($crsinfo{$cdom.'_'.$cnum}) eq 'HASH') {
8163: $courses{$cid} = $crsinfo{$cid};
8164: $crstype = $crsinfo{$cid}{'type'};
8165: $desc = $crsinfo{$cid}{'description'};
8166: } else {
8167: $missing{$cid} = 1;
8168: }
8169: }
8170: $extra = &mt($crstype).': <a href="/public/'.$cdom.'/'.$cnum.'/syllabus">'.$desc.'</a>';
1.406.2.6 raeburn 8171: if ($sec ne '') {
8172: $extra .= ' ('.&mt('Section: [_1]',$sec).')';
8173: }
1.406.2.5 raeburn 8174: } elsif ($extent =~ m{^/($match_domain)/($match_username|$)}) {
8175: my ($dom,$name) = ($1,$2);
8176: if ($rolecode eq 'au') {
8177: $extra = '';
8178: } elsif ($rolecode =~ /^(ca|aa)$/) {
8179: $extra = &mt('Authoring Space: [_1]',$name.':'.$dom);
8180: } elsif ($rolecode =~ /^(li|dg|dh|dc|sc)$/) {
8181: $extra = &mt('Domain: [_1]',$dom);
8182: }
8183: }
8184: my $rolename;
8185: if ($rolecode =~ m{^cr/($match_domain)/($match_username)/(\w+)}) {
8186: my $role = $3;
8187: my $owner = "($2:$1)";
8188: if ($2 eq $1.'-domainconfig') {
8189: $owner = '(ad hoc)';
8190: }
8191: $rolename = &mt('Custom role: [_1]',$role.' '.$owner);
8192: } else {
8193: $rolename = &Apache::lonnet::plaintext($rolecode,$crstype);
8194: }
8195: $shown = &mt('Role selection: [_1]',$rolename);
8196: } else {
8197: $shown = &mt($event);
1.406.2.13 raeburn 8198: if ($data =~ /^webdav/) {
8199: my ($path,$clientip) = split(/\s+/,$data,2);
8200: $path =~ s/^webdav//;
8201: if ($clientip ne '') {
8202: $extra = &mt('Client IP address: [_1]',$clientip);
8203: }
8204: if ($path ne '') {
8205: $shown .= ' '.&mt('(WebDAV access to [_1])',$path);
8206: }
8207: } elsif ($data ne '') {
8208: $extra = &mt('Client IP address: [_1]',$data);
1.406.2.5 raeburn 8209: }
8210: }
8211: $r->print(
8212: &Apache::loncommon::start_data_table_row()
8213: .'<td>'.$count.'</td>'
8214: .'<td>'.&Apache::lonlocal::locallocaltime($timestamp).'</td>'
8215: .'<td>'.$host.'</td>'
8216: .'<td>'.$shown.'</td>'
8217: .'<td>'.$extra.'</td>'
8218: .&Apache::loncommon::end_data_table_row()."\n");
8219: }
8220: }
8221:
8222: if ($showntableheader) { # Table footer, if content displayed above
8223: $r->print(&Apache::loncommon::end_data_table().
8224: &userlogdisplay_navlinks(\%curr,$more_records));
8225: } else { # No content displayed above
1.406.2.18 raeburn 8226: $r->print($heading.'<p class="LC_info">'
1.406.2.5 raeburn 8227: .&mt('There are no records to display.')
8228: .'</p>');
8229: }
8230:
1.406.2.8 raeburn 8231: if ($env{'form.popup'} == 1) {
8232: $r->print('<input type="hidden" name="popup" value="1" />'."\n");
8233: }
8234:
1.406.2.5 raeburn 8235: # Form Footer
8236: $r->print(
8237: '<input type="hidden" name="currstate" value="" />'
8238: .'<input type="hidden" name="accessuname" value="'.$uname.'" />'
8239: .'<input type="hidden" name="accessudom" value="'.$udom.'" />'
8240: .'<input type="hidden" name="page" value="'.$curr{'page'}.'" />'
8241: .'<input type="hidden" name="prevphases" value="'.$prevphasestr.'" />'
8242: .'<input type="hidden" name="phase" value="activity" />'
8243: .'<input type="hidden" name="action" value="accesslogs" />'
8244: .'<input type="hidden" name="srchdomain" value="'.$udom.'" />'
8245: .'<input type="hidden" name="srchby" value="'.$env{'form.srchby'}.'" />'
8246: .'<input type="hidden" name="srchtype" value="'.$env{'form.srchtype'}.'" />'
8247: .'<input type="hidden" name="srchterm" value="'.&HTML::Entities::encode($env{'form.srchterm'},'<>"&').'" />'
8248: .'<input type="hidden" name="srchin" value="'.$env{'form.srchin'}.'" />'
8249: .'</form>');
8250: return;
8251: }
8252:
8253: sub earlyout_accesslog_form {
8254: my ($formname,$prevphasestr,$udom) = @_;
8255: my $srchterm = &HTML::Entities::encode($env{'form.srchterm'},'<>"&');
8256: return <<"END";
8257: <form action="/adm/createuser" method="post" name="$formname">
8258: <input type="hidden" name="currstate" value="" />
8259: <input type="hidden" name="prevphases" value="$prevphasestr" />
8260: <input type="hidden" name="phase" value="activity" />
8261: <input type="hidden" name="action" value="accesslogs" />
8262: <input type="hidden" name="srchdomain" value="$udom" />
8263: <input type="hidden" name="srchby" value="$env{'form.srchby'}" />
8264: <input type="hidden" name="srchtype" value="$env{'form.srchtype'}" />
8265: <input type="hidden" name="srchterm" value="$srchterm" />
8266: <input type="hidden" name="srchin" value="$env{'form.srchin'}" />
8267: </form>
8268: END
8269: }
8270:
8271: sub activity_display_filter {
8272: my ($formname,$curr) = @_;
8273: my $nolink = 1;
8274: my $output = '<table><tr><td valign="top">'.
8275: '<span class="LC_nobreak"><b>'.&mt('Actions/page:').'</b></span><br />'.
8276: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
8277: (&mt('all'),5,10,20,50,100,1000,10000)).
8278: '</td><td> </td>';
8279: my $startform =
8280: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_start_date',
8281: $curr->{'accesslog_start_date'},undef,
8282: undef,undef,undef,undef,undef,undef,$nolink);
8283: my $endform =
8284: &Apache::lonhtmlcommon::date_setter($formname,'accesslog_end_date',
8285: $curr->{'accesslog_end_date'},undef,
8286: undef,undef,undef,undef,undef,undef,$nolink);
8287: my %lt = &Apache::lonlocal::texthash (
8288: activity => 'Activity',
8289: Role => 'Role selection',
8290: log => 'Log-in or Logout',
8291: );
8292: $output .= '<td valign="top"><b>'.&mt('Window during which actions occurred:').'</b><br />'.
8293: '<table><tr><td>'.&mt('After:').
8294: '</td><td>'.$startform.'</td></tr>'.
8295: '<tr><td>'.&mt('Before:').'</td>'.
8296: '<td>'.$endform.'</td></tr></table>'.
8297: '</td>'.
8298: '<td> </td>'.
8299: '<td valign="top"><b>'.&mt('Activities').'</b><br />'.
8300: '<select name="activity"><option value="any"';
8301: if ($curr->{'activity'} eq 'any') {
8302: $output .= ' selected="selected"';
8303: }
8304: $output .= '>'.&mt('Any').'</option>'."\n";
8305: foreach my $activity ('Role','log') {
8306: my $selstr = '';
8307: if ($activity eq $curr->{'activity'}) {
8308: $selstr = ' selected="selected"';
8309: }
8310: $output .= '<option value="'.$activity.'"'.$selstr.'>'.$lt{$activity}.'</option>';
8311: }
8312: $output .= '</select></td>'.
8313: '</tr></table>';
8314: # Update Display button
8315: $output .= '<p>'
8316: .'<input type="submit" value="'.&mt('Update Display').'" />'
1.406.2.12 raeburn 8317: .'</p><hr />';
1.406.2.5 raeburn 8318: return $output;
8319: }
8320:
8321: sub userlogdisplay_js {
8322: my ($formname) = @_;
8323: return <<"ENDSCRIPT";
8324:
1.239 raeburn 8325: function chgPage(caller) {
8326: if (caller == 'previous') {
8327: document.$formname.page.value --;
8328: }
8329: if (caller == 'next') {
8330: document.$formname.page.value ++;
8331: }
1.327 raeburn 8332: document.$formname.submit();
1.239 raeburn 8333: return;
8334: }
8335: ENDSCRIPT
1.406.2.5 raeburn 8336: }
8337:
8338: sub userlogdisplay_navlinks {
8339: my ($curr,$more_records) = @_;
8340: return unless(ref($curr) eq 'HASH');
8341: # Navigation Buttons
8342: my $nav_links = '<p>';
8343: if (($curr->{'page'} > 1) || ($more_records)) {
8344: if (($curr->{'page'} > 1) && ($curr->{'show'} !~ /\D/)) {
8345: $nav_links .= '<input type="button"'
8346: .' onclick="javascript:chgPage('."'previous'".');"'
8347: .' value="'.&mt('Previous [_1] changes',$curr->{'show'})
8348: .'" /> ';
8349: }
8350: if ($more_records) {
8351: $nav_links .= '<input type="button"'
8352: .' onclick="javascript:chgPage('."'next'".');"'
8353: .' value="'.&mt('Next [_1] changes',$curr->{'show'})
8354: .'" />';
1.301 bisitz 8355: }
8356: }
1.406.2.5 raeburn 8357: $nav_links .= '</p>';
8358: return $nav_links;
1.239 raeburn 8359: }
8360:
8361: sub role_display_filter {
1.363 raeburn 8362: my ($context,$formname,$cdom,$cnum,$curr,$version,$crstype) = @_;
8363: my $lctype;
8364: if ($context eq 'course') {
8365: $lctype = lc($crstype);
8366: }
1.239 raeburn 8367: my $nolink = 1;
8368: my $output = '<table><tr><td valign="top">'.
1.301 bisitz 8369: '<span class="LC_nobreak"><b>'.&mt('Changes/page:').'</b></span><br />'.
1.239 raeburn 8370: &Apache::lonmeta::selectbox('show',$curr->{'show'},undef,
8371: (&mt('all'),5,10,20,50,100,1000,10000)).
8372: '</td><td> </td>';
8373: my $startform =
8374: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_start_date',
8375: $curr->{'rolelog_start_date'},undef,
8376: undef,undef,undef,undef,undef,undef,$nolink);
8377: my $endform =
8378: &Apache::lonhtmlcommon::date_setter($formname,'rolelog_end_date',
8379: $curr->{'rolelog_end_date'},undef,
8380: undef,undef,undef,undef,undef,undef,$nolink);
1.363 raeburn 8381: my %lt = &rolechg_contexts($context,$crstype);
1.301 bisitz 8382: $output .= '<td valign="top"><b>'.&mt('Window during which changes occurred:').'</b><br />'.
8383: '<table><tr><td>'.&mt('After:').
8384: '</td><td>'.$startform.'</td></tr>'.
8385: '<tr><td>'.&mt('Before:').'</td>'.
8386: '<td>'.$endform.'</td></tr></table>'.
8387: '</td>'.
8388: '<td> </td>'.
1.239 raeburn 8389: '<td valign="top"><b>'.&mt('Role:').'</b><br />'.
8390: '<select name="role"><option value="any"';
8391: if ($curr->{'role'} eq 'any') {
8392: $output .= ' selected="selected"';
8393: }
8394: $output .= '>'.&mt('Any').'</option>'."\n";
1.363 raeburn 8395: my @roles = &Apache::lonuserutils::roles_by_context($context,1,$crstype);
1.239 raeburn 8396: foreach my $role (@roles) {
8397: my $plrole;
8398: if ($role eq 'cr') {
8399: $plrole = &mt('Custom Role');
8400: } else {
1.318 raeburn 8401: $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.239 raeburn 8402: }
8403: my $selstr = '';
8404: if ($role eq $curr->{'role'}) {
8405: $selstr = ' selected="selected"';
8406: }
8407: $output .= ' <option value="'.$role.'"'.$selstr.'>'.$plrole.'</option>';
8408: }
1.301 bisitz 8409: $output .= '</select></td>'.
8410: '<td> </td>'.
8411: '<td valign="top"><b>'.
1.239 raeburn 8412: &mt('Context:').'</b><br /><select name="chgcontext">';
1.363 raeburn 8413: my @posscontexts;
8414: if ($context eq 'course') {
1.406.2.20 raeburn 8415: @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
1.363 raeburn 8416: } elsif ($context eq 'domain') {
8417: @posscontexts = ('any','domain','requestauthor','domconfig','server');
8418: } else {
1.406.2.20.2. (raeburn 8419:): @posscontexts = ('any','author','coauthor','domain');
1.406.2.20 raeburn 8420: }
1.363 raeburn 8421: foreach my $chgtype (@posscontexts) {
1.239 raeburn 8422: my $selstr = '';
8423: if ($curr->{'chgcontext'} eq $chgtype) {
1.301 bisitz 8424: $selstr = ' selected="selected"';
1.239 raeburn 8425: }
1.363 raeburn 8426: if ($context eq 'course') {
1.376 raeburn 8427: if (($chgtype eq 'automated') || ($chgtype eq 'updatenow')) {
1.363 raeburn 8428: next if (!&Apache::lonnet::auto_run($cnum,$cdom));
8429: }
1.239 raeburn 8430: }
8431: $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
1.248 raeburn 8432: }
1.303 bisitz 8433: $output .= '</select></td>'
8434: .'</tr></table>';
8435:
8436: # Update Display button
8437: $output .= '<p>'
8438: .'<input type="submit" value="'.&mt('Update Display').'" />'
8439: .'</p>';
8440:
8441: # Server version info
1.363 raeburn 8442: my $needsrev = '2.11.0';
8443: if ($context eq 'course') {
8444: $needsrev = '2.7.0';
8445: }
8446:
1.303 bisitz 8447: $output .= '<p class="LC_info">'
8448: .&mt('Only changes made from servers running LON-CAPA [_1] or later are displayed.'
1.363 raeburn 8449: ,$needsrev);
1.248 raeburn 8450: if ($version) {
1.303 bisitz 8451: $output .= ' '.&mt('This LON-CAPA server is version [_1]',$version);
8452: }
8453: $output .= '</p><hr />';
1.239 raeburn 8454: return $output;
8455: }
8456:
8457: sub rolechg_contexts {
1.363 raeburn 8458: my ($context,$crstype) = @_;
8459: my %lt;
8460: if ($context eq 'course') {
8461: %lt = &Apache::lonlocal::texthash (
1.239 raeburn 8462: any => 'Any',
1.376 raeburn 8463: automated => 'Automated Enrollment',
1.406.2.20 raeburn 8464: chgtype => 'Enrollment Type/Lock Change',
1.239 raeburn 8465: updatenow => 'Roster Update',
8466: createcourse => 'Course Creation',
8467: course => 'User Management in course',
8468: domain => 'User Management in domain',
1.313 raeburn 8469: selfenroll => 'Self-enrolled',
1.318 raeburn 8470: requestcourses => 'Course Request',
1.239 raeburn 8471: );
1.363 raeburn 8472: if ($crstype eq 'Community') {
8473: $lt{'createcourse'} = &mt('Community Creation');
8474: $lt{'course'} = &mt('User Management in community');
8475: $lt{'requestcourses'} = &mt('Community Request');
8476: }
8477: } elsif ($context eq 'domain') {
8478: %lt = &Apache::lonlocal::texthash (
8479: any => 'Any',
8480: domain => 'User Management in domain',
8481: requestauthor => 'Authoring Request',
8482: server => 'Command line script (DC role)',
8483: domconfig => 'Self-enrolled',
8484: );
8485: } else {
8486: %lt = &Apache::lonlocal::texthash (
8487: any => 'Any',
8488: domain => 'User Management in domain',
8489: author => 'User Management by author',
1.406.2.20.2. (raeburn 8490:): coauthor => 'User Management by coauthor',
1.363 raeburn 8491: );
8492: }
1.239 raeburn 8493: return %lt;
8494: }
8495:
1.406.2.10 raeburn 8496: sub print_helpdeskaccess_display {
8497: my ($r,$permission,$brcrum) = @_;
8498: my $formname = 'helpdeskaccess';
8499: my $helpitem = 'Course_Helpdesk_Access';
8500: push (@{$brcrum},
8501: {href => '/adm/createuser?action=helpdesk',
8502: text => 'Helpdesk Access',
8503: help => $helpitem});
8504: my $bread_crumbs_component = 'Helpdesk Staff Access';
8505: my $args = { bread_crumbs => $brcrum,
8506: bread_crumbs_component => $bread_crumbs_component};
8507:
8508: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8509: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
8510: my $confname = $cdom.'-domainconfig';
8511: my $crstype = &Apache::loncommon::course_type();
8512:
1.406.2.12 raeburn 8513: my @accesstypes = ('all','dh','da','none');
1.406.2.10 raeburn 8514: my ($numstatustypes,@jsarray);
8515: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
8516: if (ref($types) eq 'ARRAY') {
8517: if (@{$types} > 0) {
8518: $numstatustypes = scalar(@{$types});
8519: push(@accesstypes,'status');
8520: @jsarray = ('bystatus');
8521: }
8522: }
8523: my %customroles = &get_domain_customroles($cdom,$confname);
1.406.2.12 raeburn 8524: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 8525: if (keys(%domhelpdesk)) {
8526: push(@accesstypes,('inc','exc'));
8527: push(@jsarray,('notinc','notexc'));
8528: }
8529: push(@jsarray,'privs');
8530: my $hiddenstr = join("','",@jsarray);
8531: my $rolestr = join("','",sort(keys(%customroles)));
8532:
8533: my $jscript;
8534: my (%settings,%overridden);
8535: if (keys(%customroles)) {
8536: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
8537: $types,\%customroles,\%settings,\%overridden);
8538: my %jsfull=();
8539: my %jslevels= (
8540: course => {},
8541: domain => {},
8542: system => {},
8543: );
8544: my %jslevelscurrent=(
8545: course => {},
8546: domain => {},
8547: system => {},
8548: );
8549: my (%privs,%jsprivs);
8550: &Apache::lonuserutils::custom_role_privs(\%privs,\%jsfull,\%jslevels,\%jslevelscurrent);
8551: foreach my $priv (keys(%jsfull)) {
8552: if ($jslevels{'course'}{$priv}) {
8553: $jsprivs{$priv} = 1;
8554: }
8555: }
8556: my (%elements,%stored);
8557: foreach my $role (keys(%customroles)) {
8558: $elements{$role.'_access'} = 'radio';
8559: $elements{$role.'_incrs'} = 'radio';
8560: if ($numstatustypes) {
8561: $elements{$role.'_status'} = 'checkbox';
8562: }
8563: if (keys(%domhelpdesk) > 0) {
8564: $elements{$role.'_staff_inc'} = 'checkbox';
8565: $elements{$role.'_staff_exc'} = 'checkbox';
8566: }
8567: $elements{$role.'_override'} = 'checkbox';
8568: if (ref($settings{$role}) eq 'HASH') {
8569: if ($settings{$role}{'access'} ne '') {
8570: my $curraccess = $settings{$role}{'access'};
8571: $stored{$role.'_access'} = $curraccess;
8572: $stored{$role.'_incrs'} = 1;
8573: if ($curraccess eq 'status') {
8574: if (ref($settings{$role}{'status'}) eq 'ARRAY') {
8575: $stored{$role.'_status'} = $settings{$role}{'status'};
8576: }
8577: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
8578: if (ref($settings{$role}{$curraccess}) eq 'ARRAY') {
8579: $stored{$role.'_staff_'.$curraccess} = $settings{$role}{$curraccess};
8580: }
8581: }
8582: } else {
8583: $stored{$role.'_incrs'} = 0;
8584: }
8585: $stored{$role.'_override'} = [];
8586: if ($env{'course.'.$env{'request.course.id'}.'.internal.adhocpriv.'.$role}) {
8587: if (ref($settings{$role}{'off'}) eq 'ARRAY') {
8588: foreach my $priv (@{$settings{$role}{'off'}}) {
8589: push(@{$stored{$role.'_override'}},$priv);
8590: }
8591: }
8592: if (ref($settings{$role}{'on'}) eq 'ARRAY') {
8593: foreach my $priv (@{$settings{$role}{'on'}}) {
8594: unless (grep(/^$priv$/,@{$stored{$role.'_override'}})) {
8595: push(@{$stored{$role.'_override'}},$priv);
8596: }
8597: }
8598: }
8599: }
8600: } else {
8601: $stored{$role.'_incrs'} = 0;
8602: }
8603: }
8604: $jscript = &Apache::lonhtmlcommon::set_form_elements(\%elements,\%stored);
8605: }
8606:
8607: my $js = <<"ENDJS";
8608: <script type="text/javascript">
8609: // <![CDATA[
8610: $jscript;
8611:
8612: function switchRoleTab(caller,role) {
8613: if (document.getElementById(role+'_maindiv')) {
8614: if (caller.id != 'LC_current_minitab') {
8615: if (document.getElementById('LC_current_minitab')) {
8616: document.getElementById('LC_current_minitab').id=null;
8617: }
8618: var roledivs = Array('$rolestr');
8619: if (roledivs.length > 0) {
8620: for (var i=0; i<roledivs.length; i++) {
8621: if (document.getElementById(roledivs[i]+'_maindiv')) {
8622: document.getElementById(roledivs[i]+'_maindiv').style.display='none';
8623: }
8624: }
8625: }
8626: caller.id = 'LC_current_minitab';
8627: document.getElementById(role+'_maindiv').style.display='block';
8628: }
8629: }
8630: return false;
8631: }
8632:
8633: function helpdeskAccess(role) {
8634: var curraccess = null;
8635: if (document.$formname.elements[role+'_access'].length) {
8636: for (var i=0; i<document.$formname.elements[role+'_access'].length; i++) {
8637: if (document.$formname.elements[role+'_access'][i].checked) {
8638: curraccess = document.$formname.elements[role+'_access'][i].value;
8639: }
8640: }
8641: }
8642: var shown = Array();
8643: var hidden = Array();
8644: if (curraccess == 'none') {
8645: hidden = Array ('$hiddenstr');
8646: } else {
8647: if (curraccess == 'status') {
8648: shown = Array ('bystatus','privs');
8649: hidden = Array ('notinc','notexc');
8650: } else {
8651: if (curraccess == 'exc') {
8652: shown = Array ('notexc','privs');
8653: hidden = Array ('notinc','bystatus');
8654: }
8655: if (curraccess == 'inc') {
8656: shown = Array ('notinc','privs');
8657: hidden = Array ('notexc','bystatus');
8658: }
8659: if (curraccess == 'all') {
8660: shown = Array ('privs');
8661: hidden = Array ('notinc','notexc','bystatus');
8662: }
8663: }
8664: }
8665: if (hidden.length > 0) {
8666: for (var i=0; i<hidden.length; i++) {
8667: if (document.getElementById(role+'_'+hidden[i])) {
8668: document.getElementById(role+'_'+hidden[i]).style.display = 'none';
8669: }
8670: }
8671: }
8672: if (shown.length > 0) {
8673: for (var i=0; i<shown.length; i++) {
8674: if (document.getElementById(role+'_'+shown[i])) {
8675: if (shown[i] == 'privs') {
8676: document.getElementById(role+'_'+shown[i]).style.display = 'block';
8677: } else {
8678: document.getElementById(role+'_'+shown[i]).style.display = 'inline';
8679: }
8680: }
8681: }
8682: }
8683: return;
8684: }
8685:
8686: function toggleAccess(role) {
8687: if ((document.getElementById(role+'_setincrs')) &&
8688: (document.getElementById(role+'_setindom'))) {
8689: for (var i=0; i<document.$formname.elements[role+'_incrs'].length; i++) {
8690: if (document.$formname.elements[role+'_incrs'][i].checked) {
8691: if (document.$formname.elements[role+'_incrs'][i].value == 1) {
8692: document.getElementById(role+'_setindom').style.display = 'none';
8693: document.getElementById(role+'_setincrs').style.display = 'block';
8694: } else {
8695: document.getElementById(role+'_setincrs').style.display = 'none';
8696: document.getElementById(role+'_setindom').style.display = 'block';
8697: }
8698: break;
8699: }
8700: }
8701: }
8702: return;
8703: }
8704:
8705: // ]]>
8706: </script>
8707: ENDJS
8708:
8709: $args->{add_entries} = {onload => "javascript:setFormElements(document.$formname)"};
8710:
8711: # print page header
8712: $r->print(&header($js,$args));
8713: # print form header
8714: $r->print('<form action="/adm/createuser" method="post" name="'.$formname.'">');
8715:
8716: if (keys(%customroles)) {
8717: my %lt = &Apache::lonlocal::texthash(
8718: 'aco' => 'As course owner you may override the defaults set in the domain for role usage and/or privileges.',
8719: 'rou' => 'Role usage',
8720: 'whi' => 'Which helpdesk personnel may use this role?',
8721: 'udd' => 'Use domain default',
1.406.2.12 raeburn 8722: 'all' => 'All with domain helpdesk or helpdesk assistant role',
8723: 'dh' => 'All with domain helpdesk role',
8724: 'da' => 'All with domain helpdesk assistant role',
1.406.2.10 raeburn 8725: 'none' => 'None',
8726: 'status' => 'Determined based on institutional status',
8727: 'inc' => 'Include all, but exclude specific personnel',
8728: 'exc' => 'Exclude all, but include specific personnel',
8729: 'hel' => 'Helpdesk',
8730: 'rpr' => 'Role privileges',
8731: );
8732: $lt{'tfh'} = &mt("Custom [_1]ad hoc[_2] course roles available for use by the domain's helpdesk are as follows",'<i>','</i>');
8733: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
8734: my (%domcurrent,%ordered,%description,%domusage,$disabled);
8735: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8736: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
8737: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
8738: }
8739: }
8740: my $count = 0;
8741: foreach my $role (sort(keys(%customroles))) {
8742: my ($order,$desc,$access_in_dom);
8743: if (ref($domcurrent{$role}) eq 'HASH') {
8744: $order = $domcurrent{$role}{'order'};
8745: $desc = $domcurrent{$role}{'desc'};
8746: $access_in_dom = $domcurrent{$role}{'access'};
8747: }
8748: if ($order eq '') {
8749: $order = $count;
8750: }
8751: $ordered{$order} = $role;
8752: if ($desc ne '') {
8753: $description{$role} = $desc;
8754: } else {
8755: $description{$role}= $role;
8756: }
8757: $count++;
8758: }
8759: %domusage = &domain_adhoc_access(\%customroles,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
8760: my @roles_by_num = ();
8761: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
8762: push(@roles_by_num,$ordered{$item});
8763: }
8764: $r->print('<p>'.$lt{'tfh'}.': <i>'.join('</i>, <i>',map { $description{$_}; } @roles_by_num).'</i>.');
8765: if ($permission->{'owner'}) {
8766: $r->print('<br />'.$lt{'aco'}.'</p><p>');
8767: $r->print('<input type="hidden" name="state" value="process" />'.
8768: '<input type="submit" value="'.&mt('Save changes').'" />');
8769: } else {
8770: if ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'}) {
8771: my ($ownername,$ownerdom) = split(/:/,$env{'course.'.$env{'request.course.id'}.'.internal.courseowner'});
8772: $r->print('<br />'.&mt('The course owner -- [_1] -- can override the default access and/or privileges for these ad hoc roles.',
8773: &Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($ownername,$ownerdom),$ownername,$ownerdom)));
8774: }
8775: $disabled = ' disabled="disabled"';
8776: }
8777: $r->print('</p>');
8778:
8779: $r->print('<div id="LC_minitab_header"><ul>');
8780: my $count = 0;
8781: my %visibility;
8782: foreach my $role (@roles_by_num) {
8783: my $id;
8784: if ($count == 0) {
8785: $id=' id="LC_current_minitab"';
8786: $visibility{$role} = ' style="display:block"';
8787: } else {
8788: $visibility{$role} = ' style="display:none"';
8789: }
8790: $count ++;
8791: $r->print('<li'.$id.'><a href="#" onclick="javascript:switchRoleTab(this.parentNode,'."'$role'".');">'.$description{$role}.'</a></li>');
8792: }
8793: $r->print('</ul></div>');
8794:
8795: foreach my $role (@roles_by_num) {
8796: my %usecheck = (
8797: all => ' checked="checked"',
8798: );
8799: my %displaydiv = (
8800: status => 'none',
8801: inc => 'none',
8802: exc => 'none',
8803: priv => 'block',
8804: );
8805: my (%selected,$overridden,$incrscheck,$indomcheck,$indomvis,$incrsvis);
8806: if (ref($settings{$role}) eq 'HASH') {
8807: if ($settings{$role}{'access'} ne '') {
8808: $indomvis = ' style="display:none"';
8809: $incrsvis = ' style="display:block"';
8810: $incrscheck = ' checked="checked"';
8811: if ($settings{$role}{'access'} ne 'all') {
8812: $usecheck{$settings{$role}{'access'}} = $usecheck{'all'};
8813: delete($usecheck{'all'});
8814: if ($settings{$role}{'access'} eq 'status') {
8815: my $access = 'status';
8816: $displaydiv{$access} = 'inline';
8817: if (ref($settings{$role}{$access}) eq 'ARRAY') {
8818: $selected{$access} = $settings{$role}{$access};
8819: }
8820: } elsif ($settings{$role}{'access'} =~ /^(inc|exc)$/) {
8821: my $access = $1;
8822: $displaydiv{$access} = 'inline';
8823: if (ref($settings{$role}{$access}) eq 'ARRAY') {
8824: $selected{$access} = $settings{$role}{$access};
8825: }
8826: } elsif ($settings{$role}{'access'} eq 'none') {
8827: $displaydiv{'priv'} = 'none';
8828: }
8829: }
8830: } else {
8831: $indomcheck = ' checked="checked"';
8832: $indomvis = ' style="display:block"';
8833: $incrsvis = ' style="display:none"';
8834: }
8835: } else {
8836: $indomcheck = ' checked="checked"';
8837: $indomvis = ' style="display:block"';
8838: $incrsvis = ' style="display:none"';
8839: }
8840: $r->print('<div class="LC_left_float" id="'.$role.'_maindiv"'.$visibility{$role}.'>'.
8841: '<fieldset><legend>'.$lt{'rou'}.'</legend>'.
8842: '<p>'.$lt{'whi'}.' <span class="LC_nobreak">'.
8843: '<label><input type="radio" name="'.$role.'_incrs" value="1"'.$incrscheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
8844: &mt('Set here in [_1]',lc($crstype)).'</label>'.
8845: '<span>'.(' 'x2).
8846: '<label><input type="radio" name="'.$role.'_incrs" value="0"'.$indomcheck.' onclick="toggleAccess('."'$role'".');"'.$disabled.'>'.
8847: $lt{'udd'}.'</label><span></p>'.
8848: '<div id="'.$role.'_setindom"'.$indomvis.'>'.
8849: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span></div>'.
8850: '<div id="'.$role.'_setincrs"'.$incrsvis.'>');
8851: foreach my $access (@accesstypes) {
8852: $r->print('<p><label><input type="radio" name="'.$role.'_access" value="'.$access.'" '.$usecheck{$access}.
8853: ' onclick="helpdeskAccess('."'$role'".');"'.$disabled.' />'.$lt{$access}.'</label>');
8854: if ($access eq 'status') {
8855: $r->print('<div id="'.$role.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
8856: &Apache::lonuserutils::adhoc_status_types($cdom,undef,$role,$selected{$access},
8857: $othertitle,$usertypes,$types,$disabled).
8858: '</div>');
8859: } elsif (($access eq 'inc') && (keys(%domhelpdesk) > 0)) {
8860: $r->print('<div id="'.$role.'_notinc" style="display:'.$displaydiv{$access}.'">'.
8861: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
8862: \%domhelpdesk,$disabled).
8863: '</div>');
8864: } elsif (($access eq 'exc') && (keys(%domhelpdesk) > 0)) {
8865: $r->print('<div id="'.$role.'_notexc" style="display:'.$displaydiv{$access}.'">'.
8866: &Apache::lonuserutils::adhoc_staff($access,undef,$role,$selected{$access},
8867: \%domhelpdesk,$disabled).
8868: '</div>');
8869: }
8870: $r->print('</p>');
8871: }
8872: $r->print('</div></fieldset>');
8873: my %full=();
8874: my %levels= (
8875: course => {},
8876: domain => {},
8877: system => {},
8878: );
8879: my %levelscurrent=(
8880: course => {},
8881: domain => {},
8882: system => {},
8883: );
8884: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
8885: $r->print('<fieldset id="'.$role.'_privs" style="display:'.$displaydiv{'priv'}.'">'.
8886: '<legend>'.$lt{'rpr'}.'</legend>'.
8887: &role_priv_table($role,$permission,$crstype,\%full,\%levels,\%levelscurrent,$overridden{$role}).
8888: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>');
8889: }
8890: if ($permission->{'owner'}) {
8891: $r->print('<p><input type="submit" value="'.&mt('Save changes').'" /></p>');
8892: }
8893: } else {
8894: $r->print(&mt('Helpdesk roles have not yet been created in this domain.'));
8895: }
8896: # Form Footer
8897: $r->print('<input type="hidden" name="action" value="helpdesk" />'
8898: .'</form>');
8899: return;
8900: }
8901:
8902: sub domain_adhoc_access {
8903: my ($roles,$domcurrent,$accesstypes,$usertypes,$othertitle) = @_;
8904: my %domusage;
8905: return unless ((ref($roles) eq 'HASH') && (ref($domcurrent) eq 'HASH') && (ref($accesstypes) eq 'ARRAY'));
8906: foreach my $role (keys(%{$roles})) {
8907: if (ref($domcurrent->{$role}) eq 'HASH') {
8908: my $access = $domcurrent->{$role}{'access'};
8909: if (($access eq '') || (!grep(/^\Q$access\E$/,@{$accesstypes}))) {
8910: $access = 'all';
1.406.2.12 raeburn 8911: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',&Apache::lonnet::plaintext('dh'),
8912: &Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8913: } elsif ($access eq 'status') {
8914: if (ref($domcurrent->{$role}{$access}) eq 'ARRAY') {
8915: my @shown;
8916: foreach my $type (@{$domcurrent->{$role}{$access}}) {
8917: unless ($type eq 'default') {
8918: if ($usertypes->{$type}) {
8919: push(@shown,$usertypes->{$type});
8920: }
8921: }
8922: }
8923: if (grep(/^default$/,@{$domcurrent->{$role}{$access}})) {
8924: push(@shown,$othertitle);
8925: }
8926: if (@shown) {
8927: my $shownstatus = join(' '.&mt('or').' ',@shown);
1.406.2.12 raeburn 8928: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role, and institutional status: [_3]',
8929: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownstatus);
1.406.2.10 raeburn 8930: } else {
8931: $domusage{$role} = &mt('No one in the domain');
8932: }
8933: }
8934: } elsif ($access eq 'inc') {
8935: my @dominc = ();
8936: if (ref($domcurrent->{$role}{'inc'}) eq 'ARRAY') {
8937: foreach my $user (@{$domcurrent->{$role}{'inc'}}) {
8938: my ($uname,$udom) = split(/:/,$user);
8939: push(@dominc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8940: }
8941: my $showninc = join(', ',@dominc);
8942: if ($showninc ne '') {
1.406.2.12 raeburn 8943: $domusage{$role} = &mt('Include any user in domain with active [_1] or [_2] role, except: [_3]',
8944: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$showninc);
1.406.2.10 raeburn 8945: } else {
1.406.2.12 raeburn 8946: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8947: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8948: }
8949: }
8950: } elsif ($access eq 'exc') {
8951: my @domexc = ();
8952: if (ref($domcurrent->{$role}{'exc'}) eq 'ARRAY') {
8953: foreach my $user (@{$domcurrent->{$role}{'exc'}}) {
8954: my ($uname,$udom) = split(/:/,$user);
8955: push(@domexc,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom),$uname,$udom));
8956: }
8957: }
8958: my $shownexc = join(', ',@domexc);
8959: if ($shownexc ne '') {
1.406.2.12 raeburn 8960: $domusage{$role} = &mt('Only the following in the domain with active [_1] or [_2] role: [_3]',
8961: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'),$shownexc);
1.406.2.10 raeburn 8962: } else {
8963: $domusage{$role} = &mt('No one in the domain');
8964: }
8965: } elsif ($access eq 'none') {
8966: $domusage{$role} = &mt('No one in the domain');
1.406.2.12 raeburn 8967: } elsif ($access eq 'dh') {
1.406.2.10 raeburn 8968: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('dh'));
1.406.2.12 raeburn 8969: } elsif ($access eq 'da') {
8970: $domusage{$role} = &mt('Any user in domain with active [_1] role',&Apache::lonnet::plaintext('da'));
8971: } elsif ($access eq 'all') {
8972: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8973: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8974: }
8975: } else {
1.406.2.12 raeburn 8976: $domusage{$role} = &mt('Any user in domain with active [_1] or [_2] role',
8977: &Apache::lonnet::plaintext('dh'),&Apache::lonnet::plaintext('da'));
1.406.2.10 raeburn 8978: }
8979: }
8980: return %domusage;
8981: }
8982:
8983: sub get_domain_customroles {
8984: my ($cdom,$confname) = @_;
8985: my %existing=&Apache::lonnet::dump('roles',$cdom,$confname,'rolesdef_');
8986: my %customroles;
8987: foreach my $key (keys(%existing)) {
8988: if ($key=~/^rolesdef\_(\w+)$/) {
8989: my $rolename = $1;
8990: my %privs;
8991: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
8992: $customroles{$rolename} = \%privs;
8993: }
8994: }
8995: return %customroles;
8996: }
8997:
8998: sub role_priv_table {
8999: my ($role,$permission,$crstype,$full,$levels,$levelscurrent,$overridden) = @_;
9000: return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
9001: (ref($levelscurrent) eq 'HASH'));
9002: my %lt=&Apache::lonlocal::texthash (
9003: 'crl' => 'Course Level Privilege',
9004: 'def' => 'Domain Defaults',
9005: 'ove' => 'Override in Course',
9006: 'ine' => 'In effect',
9007: 'dis' => 'Disabled',
9008: 'ena' => 'Enabled',
9009: );
9010: if ($crstype eq 'Community') {
9011: $lt{'ove'} = 'Override in Community',
9012: }
9013: my @status = ('Disabled','Enabled');
9014: my (%on,%off);
9015: if (ref($overridden) eq 'HASH') {
9016: if (ref($overridden->{'on'}) eq 'ARRAY') {
9017: map { $on{$_} = 1; } (@{$overridden->{'on'}});
9018: }
9019: if (ref($overridden->{'off'}) eq 'ARRAY') {
9020: map { $off{$_} = 1; } (@{$overridden->{'off'}});
9021: }
9022: }
9023: my $output=&Apache::loncommon::start_data_table().
9024: &Apache::loncommon::start_data_table_header_row().
9025: '<th>'.$lt{'crl'}.'</th><th>'.$lt{'def'}.'</th><th>'.$lt{'ove'}.
9026: '</th><th>'.$lt{'ine'}.'</th>'.
9027: &Apache::loncommon::end_data_table_header_row();
9028: foreach my $priv (sort(keys(%{$full}))) {
9029: next unless ($levels->{'course'}{$priv});
9030: my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
9031: my ($default,$ineffect);
9032: if ($levelscurrent->{'course'}{$priv}) {
9033: $default = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9034: $ineffect = $default;
9035: }
9036: my ($customstatus,$checked);
9037: $output .= &Apache::loncommon::start_data_table_row().
9038: '<td>'.$privtext.'</td>'.
9039: '<td>'.$default.'</td><td>';
9040: if (($levelscurrent->{'course'}{$priv}) && ($off{$priv})) {
9041: if ($permission->{'owner'}) {
9042: $checked = ' checked="checked"';
9043: }
9044: $customstatus = '<img src="/adm/lonIcons/navmap.wrong.gif" alt="'.$lt{'dis'}.'" />';
9045: $ineffect = $customstatus;
9046: } elsif ((!$levelscurrent->{'course'}{$priv}) && ($on{$priv})) {
9047: if ($permission->{'owner'}) {
9048: $checked = ' checked="checked"';
9049: }
9050: $customstatus = '<img src="/adm/lonIcons/navmap.correct.gif" alt="'.$lt{'ena'}.'" />';
9051: $ineffect = $customstatus;
9052: }
9053: if ($permission->{'owner'}) {
9054: $output .= '<input type="checkbox" name="'.$role.'_override" value="'.$priv.'"'.$checked.' />';
9055: } else {
9056: $output .= $customstatus;
9057: }
9058: $output .= '</td><td>'.$ineffect.'</td>'.
9059: &Apache::loncommon::end_data_table_row();
9060: }
9061: $output .= &Apache::loncommon::end_data_table();
9062: return $output;
9063: }
9064:
9065: sub get_adhocrole_settings {
9066: my ($cid,$accesstypes,$types,$customroles,$settings,$overridden) = @_;
9067: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($customroles) eq 'HASH') &&
9068: (ref($settings) eq 'HASH') && (ref($overridden) eq 'HASH'));
9069: foreach my $role (split(/,/,$env{'course.'.$cid.'.internal.adhocaccess'})) {
9070: my ($curraccess,$rest) = split(/=/,$env{'course.'.$cid.'.internal.adhoc.'.$role});
9071: if (($curraccess ne '') && (grep(/^\Q$curraccess\E$/,@{$accesstypes}))) {
9072: $settings->{$role}{'access'} = $curraccess;
9073: if (($curraccess eq 'status') && (ref($types) eq 'ARRAY')) {
9074: my @status = split(/,/,$rest);
9075: my @currstatus;
9076: foreach my $type (@status) {
9077: if ($type eq 'default') {
9078: push(@currstatus,$type);
9079: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9080: push(@currstatus,$type);
9081: }
9082: }
9083: if (@currstatus) {
9084: $settings->{$role}{$curraccess} = \@currstatus;
9085: } elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) {
9086: my @personnel = split(/,/,$rest);
9087: $settings->{$role}{$curraccess} = \@personnel;
9088: }
9089: }
9090: }
9091: }
9092: foreach my $role (keys(%{$customroles})) {
9093: if ($env{'course.'.$cid.'.internal.adhocpriv.'.$role}) {
9094: my %currentprivs;
9095: if (ref($customroles->{$role}) eq 'HASH') {
9096: if (exists($customroles->{$role}{'course'})) {
9097: my %full=();
9098: my %levels= (
9099: course => {},
9100: domain => {},
9101: system => {},
9102: );
9103: my %levelscurrent=(
9104: course => {},
9105: domain => {},
9106: system => {},
9107: );
9108: &Apache::lonuserutils::custom_role_privs($customroles->{$role},\%full,\%levels,\%levelscurrent);
9109: %currentprivs = %{$levelscurrent{'course'}};
9110: }
9111: }
9112: foreach my $item (split(/,/,$env{'course.'.$cid.'.internal.adhocpriv.'.$role})) {
9113: next if ($item eq '');
9114: my ($rule,$rest) = split(/=/,$item);
9115: next unless (($rule eq 'off') || ($rule eq 'on'));
9116: foreach my $priv (split(/:/,$rest)) {
9117: if ($priv ne '') {
9118: if ($rule eq 'off') {
9119: push(@{$overridden->{$role}{'off'}},$priv);
9120: if ($currentprivs{$priv}) {
9121: push(@{$settings->{$role}{'off'}},$priv);
9122: }
9123: } else {
9124: push(@{$overridden->{$role}{'on'}},$priv);
9125: unless ($currentprivs{$priv}) {
9126: push(@{$settings->{$role}{'on'}},$priv);
9127: }
9128: }
9129: }
9130: }
9131: }
9132: }
9133: }
9134: return;
9135: }
9136:
9137: sub update_helpdeskaccess {
9138: my ($r,$permission,$brcrum) = @_;
9139: my $helpitem = 'Course_Helpdesk_Access';
9140: push (@{$brcrum},
9141: {href => '/adm/createuser?action=helpdesk',
9142: text => 'Helpdesk Access',
9143: help => $helpitem},
9144: {href => '/adm/createuser?action=helpdesk',
9145: text => 'Result',
9146: help => $helpitem}
9147: );
9148: my $bread_crumbs_component = 'Helpdesk Staff Access';
9149: my $args = { bread_crumbs => $brcrum,
9150: bread_crumbs_component => $bread_crumbs_component};
9151:
9152: # print page header
9153: $r->print(&header('',$args));
9154: unless ((ref($permission) eq 'HASH') && ($permission->{'owner'})) {
9155: $r->print('<p class="LC_error">'.&mt('You do not have permission to change helpdesk access.').'</p>');
9156: return;
9157: }
1.406.2.12 raeburn 9158: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.406.2.10 raeburn 9159: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9160: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9161: my $confname = $cdom.'-domainconfig';
9162: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($cdom);
9163: my $crstype = &Apache::loncommon::course_type();
9164: my %customroles = &get_domain_customroles($cdom,$confname);
9165: my (%settings,%overridden);
9166: &get_adhocrole_settings($env{'request.course.id'},\@accesstypes,
9167: $types,\%customroles,\%settings,\%overridden);
1.406.2.12 raeburn 9168: my %domhelpdesk = &Apache::lonnet::get_active_domroles($cdom,['dh','da']);
1.406.2.10 raeburn 9169: my (%changed,%storehash,@todelete);
9170:
9171: if (keys(%customroles)) {
9172: my (%newsettings,@incrs);
9173: foreach my $role (keys(%customroles)) {
9174: $newsettings{$role} = {
9175: access => '',
9176: status => '',
9177: exc => '',
9178: inc => '',
9179: on => '',
9180: off => '',
9181: };
9182: my %current;
9183: if (ref($settings{$role}) eq 'HASH') {
9184: %current = %{$settings{$role}};
9185: }
9186: if (ref($overridden{$role}) eq 'HASH') {
9187: $current{'overridden'} = $overridden{$role};
9188: }
9189: if ($env{'form.'.$role.'_incrs'}) {
9190: my $access = $env{'form.'.$role.'_access'};
9191: if (grep(/^\Q$access\E$/,@accesstypes)) {
9192: push(@incrs,$role);
9193: unless ($current{'access'} eq $access) {
9194: $changed{$role}{'access'} = 1;
9195: $storehash{'internal.adhoc.'.$role} = $access;
9196: }
9197: if ($access eq 'status') {
9198: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$role.'_status');
9199: my @stored;
9200: my @shownstatus;
9201: if (ref($types) eq 'ARRAY') {
9202: foreach my $type (sort(@statuses)) {
9203: if ($type eq 'default') {
9204: push(@stored,$type);
9205: } elsif (grep(/^\Q$type\E$/,@{$types})) {
9206: push(@stored,$type);
9207: push(@shownstatus,$usertypes->{$type});
9208: }
9209: }
9210: if (grep(/^default$/,@statuses)) {
9211: push(@shownstatus,$othertitle);
9212: }
9213: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9214: }
9215: $newsettings{$role}{'status'} = join(' '.&mt('or').' ',@shownstatus);
9216: if (ref($current{'status'}) eq 'ARRAY') {
9217: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{'status'});
9218: if (@diffs) {
9219: $changed{$role}{'status'} = 1;
9220: }
9221: } elsif (@stored) {
9222: $changed{$role}{'status'} = 1;
9223: }
9224: } elsif (($access eq 'inc') || ($access eq 'exc')) {
9225: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$role.'_staff_'.$access);
9226: my @newspecstaff;
9227: my @stored;
9228: my @currstaff;
9229: foreach my $person (sort(@personnel)) {
9230: if ($domhelpdesk{$person}) {
9231: push(@stored,$person);
9232: }
9233: }
9234: if (ref($current{$access}) eq 'ARRAY') {
9235: my @diffs = &Apache::loncommon::compare_arrays(\@stored,$current{$access});
9236: if (@diffs) {
9237: $changed{$role}{$access} = 1;
9238: }
9239: } elsif (@stored) {
9240: $changed{$role}{$access} = 1;
9241: }
9242: $storehash{'internal.adhoc.'.$role} .= '='.join(',',@stored);
9243: foreach my $person (@stored) {
9244: my ($uname,$udom) = split(/:/,$person);
9245: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
9246: }
9247: $newsettings{$role}{$access} = join(', ',sort(@newspecstaff));
9248: }
9249: $newsettings{$role}{'access'} = $access;
9250: }
9251: } else {
9252: if (($current{'access'} ne '') && (grep(/^\Q$current{'access'}\E$/,@accesstypes))) {
9253: $changed{$role}{'access'} = 1;
9254: $newsettings{$role} = {};
9255: push(@todelete,'internal.adhoc.'.$role);
9256: }
9257: }
9258: if (($env{'form.'.$role.'_incrs'}) && ($env{'form.'.$role.'_access'} eq 'none')) {
9259: if (ref($current{'overridden'}) eq 'HASH') {
9260: push(@todelete,'internal.adhocpriv.'.$role);
9261: }
9262: } else {
9263: my %full=();
9264: my %levels= (
9265: course => {},
9266: domain => {},
9267: system => {},
9268: );
9269: my %levelscurrent=(
9270: course => {},
9271: domain => {},
9272: system => {},
9273: );
9274: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
9275: my (@updatedon,@updatedoff,@override);
9276: @override = &Apache::loncommon::get_env_multiple('form.'.$role.'_override');
9277: if (@override) {
9278: foreach my $priv (sort(keys(%full))) {
9279: next unless ($levels{'course'}{$priv});
9280: if (grep(/^\Q$priv\E$/,@override)) {
9281: if ($levelscurrent{'course'}{$priv}) {
9282: push(@updatedoff,$priv);
9283: } else {
9284: push(@updatedon,$priv);
9285: }
9286: }
9287: }
9288: }
9289: if (@updatedon) {
9290: $newsettings{$role}{'on'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedon));
9291: }
9292: if (@updatedoff) {
9293: $newsettings{$role}{'off'} = join('</li><li>', map { &Apache::lonnet::plaintext($_,$crstype) } (@updatedoff));
9294: }
9295: if (ref($current{'overridden'}) eq 'HASH') {
9296: if (ref($current{'overridden'}{'on'}) eq 'ARRAY') {
9297: if (@updatedon) {
9298: my @diffs = &Apache::loncommon::compare_arrays(\@updatedon,$current{'overridden'}{'on'});
9299: if (@diffs) {
9300: $changed{$role}{'on'} = 1;
9301: }
9302: } else {
9303: $changed{$role}{'on'} = 1;
9304: }
9305: } elsif (@updatedon) {
9306: $changed{$role}{'on'} = 1;
9307: }
9308: if (ref($current{'overridden'}{'off'}) eq 'ARRAY') {
9309: if (@updatedoff) {
9310: my @diffs = &Apache::loncommon::compare_arrays(\@updatedoff,$current{'overridden'}{'off'});
9311: if (@diffs) {
9312: $changed{$role}{'off'} = 1;
9313: }
9314: } else {
9315: $changed{$role}{'off'} = 1;
9316: }
9317: } elsif (@updatedoff) {
9318: $changed{$role}{'off'} = 1;
9319: }
9320: } else {
9321: if (@updatedon) {
9322: $changed{$role}{'on'} = 1;
9323: }
9324: if (@updatedoff) {
9325: $changed{$role}{'off'} = 1;
9326: }
9327: }
9328: if (ref($changed{$role}) eq 'HASH') {
9329: if (($changed{$role}{'on'} || $changed{$role}{'off'})) {
9330: my $newpriv;
9331: if (@updatedon) {
9332: $newpriv = 'on='.join(':',@updatedon);
9333: }
9334: if (@updatedoff) {
9335: $newpriv .= ($newpriv ? ',' : '' ).'off='.join(':',@updatedoff);
9336: }
9337: if ($newpriv eq '') {
9338: push(@todelete,'internal.adhocpriv.'.$role);
9339: } else {
9340: $storehash{'internal.adhocpriv.'.$role} = $newpriv;
9341: }
9342: }
9343: }
9344: }
9345: }
9346: if (@incrs) {
9347: $storehash{'internal.adhocaccess'} = join(',',@incrs);
9348: } elsif (@todelete) {
9349: push(@todelete,'internal.adhocaccess');
9350: }
9351: if (keys(%changed)) {
9352: my ($putres,$delres);
9353: if (keys(%storehash)) {
9354: $putres = &Apache::lonnet::put('environment',\%storehash,$cdom,$cnum);
9355: my %newenvhash;
9356: foreach my $key (keys(%storehash)) {
9357: $newenvhash{'course.'.$env{'request.course.id'}.'.'.$key} = $storehash{$key};
9358: }
9359: &Apache::lonnet::appenv(\%newenvhash);
9360: }
9361: if (@todelete) {
9362: $delres = &Apache::lonnet::del('environment',\@todelete,$cdom,$cnum);
9363: foreach my $key (@todelete) {
9364: &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.'.$key);
9365: }
9366: }
9367: if (($putres eq 'ok') || ($delres eq 'ok')) {
9368: my %domconfig = &Apache::lonnet::get_dom('configuration',['helpsettings'],$cdom);
9369: my (%domcurrent,%ordered,%description,%domusage);
9370: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
9371: if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') {
9372: %domcurrent = %{$domconfig{'helpsettings'}{'adhoc'}};
9373: }
9374: }
9375: my $count = 0;
9376: foreach my $role (sort(keys(%customroles))) {
9377: my ($order,$desc);
9378: if (ref($domcurrent{$role}) eq 'HASH') {
9379: $order = $domcurrent{$role}{'order'};
9380: $desc = $domcurrent{$role}{'desc'};
9381: }
9382: if ($order eq '') {
9383: $order = $count;
9384: }
9385: $ordered{$order} = $role;
9386: if ($desc ne '') {
9387: $description{$role} = $desc;
9388: } else {
9389: $description{$role}= $role;
9390: }
9391: $count++;
9392: }
9393: my @roles_by_num = ();
9394: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
9395: push(@roles_by_num,$ordered{$item});
9396: }
9397: %domusage = &domain_adhoc_access(\%changed,\%domcurrent,\@accesstypes,$usertypes,$othertitle);
9398: $r->print(&mt('Helpdesk access settings have been changed as follows').'<br />');
9399: $r->print('<ul>');
9400: foreach my $role (@roles_by_num) {
9401: next unless (ref($changed{$role}) eq 'HASH');
9402: $r->print('<li>'.&mt('Ad hoc role').': <b>'.$description{$role}.'</b>'.
9403: '<ul>');
9404: if ($changed{$role}{'access'} || $changed{$role}{'status'} || $changed{$role}{'inc'} || $changed{$role}{'exc'}) {
9405: $r->print('<li>');
9406: if ($env{'form.'.$role.'_incrs'}) {
9407: if ($newsettings{$role}{'access'} eq 'all') {
9408: $r->print(&mt('All helpdesk staff can access '.lc($crstype).' with this role.'));
1.406.2.12 raeburn 9409: } elsif ($newsettings{$role}{'access'} eq 'dh') {
9410: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9411: &Apache::lonnet::plaintext('dh')));
9412: } elsif ($newsettings{$role}{'access'} eq 'da') {
9413: $r->print(&mt('Helpdesk staff can use this role if they have an active [_1] role',
9414: &Apache::lonnet::plaintext('da')));
1.406.2.10 raeburn 9415: } elsif ($newsettings{$role}{'access'} eq 'none') {
9416: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9417: } elsif ($newsettings{$role}{'access'} eq 'status') {
9418: if ($newsettings{$role}{'status'}) {
9419: my ($access,$rest) = split(/=/,$storehash{'internal.adhoc.'.$role});
9420: if (split(/,/,$rest) > 1) {
9421: $r->print(&mt('Helpdesk staff can use this role if their institutional type is one of: [_1].',
9422: $newsettings{$role}{'status'}));
9423: } else {
9424: $r->print(&mt('Helpdesk staff can use this role if their institutional type is: [_1].',
9425: $newsettings{$role}{'status'}));
9426: }
9427: } else {
9428: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9429: }
9430: } elsif ($newsettings{$role}{'access'} eq 'exc') {
9431: if ($newsettings{$role}{'exc'}) {
9432: $r->print(&mt('Helpdesk staff who can use this role are as follows:').' '.$newsettings{$role}{'exc'}.'.');
9433: } else {
9434: $r->print(&mt('No helpdesk staff can access '.lc($crstype).' with this role.'));
9435: }
9436: } elsif ($newsettings{$role}{'access'} eq 'inc') {
9437: if ($newsettings{$role}{'inc'}) {
9438: $r->print(&mt('All helpdesk staff may use this role except the following:').' '.$newsettings{$role}{'inc'}.'.');
9439: } else {
9440: $r->print(&mt('All helpdesk staff may use this role.'));
9441: }
9442: }
9443: } else {
9444: $r->print(&mt('Default access set in the domain now applies.').'<br />'.
9445: '<span class="LC_cusr_emph">'.$domusage{$role}.'</span>');
9446: }
9447: $r->print('</li>');
9448: }
9449: unless ($newsettings{$role}{'access'} eq 'none') {
9450: if ($changed{$role}{'off'}) {
9451: if ($newsettings{$role}{'off'}) {
9452: $r->print('<li>'.&mt('Privileges which are available by default for this ad hoc role, but are disabled for this specific '.lc($crstype).':').
9453: '<ul><li>'.$newsettings{$role}{'off'}.'</li></ul></li>');
9454: } else {
9455: $r->print('<li>'.&mt('All privileges available by default for this ad hoc role are enabled.').'</li>');
9456: }
9457: }
9458: if ($changed{$role}{'on'}) {
9459: if ($newsettings{$role}{'on'}) {
9460: $r->print('<li>'.&mt('Privileges which are not available by default for this ad hoc role, but are enabled for this specific '.lc($crstype).':').
9461: '<ul><li>'.$newsettings{$role}{'on'}.'</li></ul></li>');
9462: } else {
9463: $r->print('<li>'.&mt('None of the privileges unavailable by default for this ad hoc role are enabled.').'</li>');
9464: }
9465: }
9466: }
9467: $r->print('</ul></li>');
9468: }
9469: $r->print('</ul>');
9470: }
9471: } else {
9472: $r->print(&mt('No changes made to helpdesk access settings.'));
9473: }
9474: }
9475: return;
9476: }
9477:
1.27 matthew 9478: #-------------------------------------------------- functions for &phase_two
1.160 raeburn 9479: sub user_search_result {
1.221 raeburn 9480: my ($context,$srch) = @_;
1.160 raeburn 9481: my %allhomes;
9482: my %inst_matches;
9483: my %srch_results;
1.181 raeburn 9484: my ($response,$currstate,$forcenewuser,$dirsrchres);
1.183 raeburn 9485: $srch->{'srchterm'} =~ s/\s+/ /g;
1.176 raeburn 9486: if ($srch->{'srchby'} !~ /^(uname|lastname|lastfirst)$/) {
1.160 raeburn 9487: $response = &mt('Invalid search.');
9488: }
9489: if ($srch->{'srchin'} !~ /^(crs|dom|alc|instd)$/) {
9490: $response = &mt('Invalid search.');
9491: }
1.177 raeburn 9492: if ($srch->{'srchtype'} !~ /^(exact|contains|begins)$/) {
1.160 raeburn 9493: $response = &mt('Invalid search.');
9494: }
9495: if ($srch->{'srchterm'} eq '') {
9496: $response = &mt('You must enter a search term.');
9497: }
1.183 raeburn 9498: if ($srch->{'srchterm'} =~ /^\s+$/) {
9499: $response = &mt('Your search term must contain more than just spaces.');
9500: }
1.160 raeburn 9501: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'instd')) {
9502: if (($srch->{'srchdomain'} eq '') ||
1.163 albertel 9503: ! (&Apache::lonnet::domain($srch->{'srchdomain'}))) {
1.160 raeburn 9504: $response = &mt('You must specify a valid domain when searching in a domain or institutional directory.')
9505: }
9506: }
9507: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs') ||
9508: ($srch->{'srchin'} eq 'alc')) {
1.176 raeburn 9509: if ($srch->{'srchby'} eq 'uname') {
1.243 raeburn 9510: my $unamecheck = $srch->{'srchterm'};
9511: if ($srch->{'srchtype'} eq 'contains') {
9512: if ($unamecheck !~ /^\w/) {
9513: $unamecheck = 'a'.$unamecheck;
9514: }
9515: }
9516: if ($unamecheck !~ /^$match_username$/) {
1.176 raeburn 9517: $response = &mt('You must specify a valid username. Only the following are allowed: letters numbers - . @');
9518: }
1.160 raeburn 9519: }
9520: }
1.180 raeburn 9521: if ($response ne '') {
1.406.2.4 raeburn 9522: $response = '<span class="LC_warning">'.$response.'</span><br />';
1.180 raeburn 9523: }
1.160 raeburn 9524: if ($srch->{'srchin'} eq 'instd') {
1.406.2.3 raeburn 9525: my $instd_chk = &instdirectorysrch_check($srch);
1.160 raeburn 9526: if ($instd_chk ne 'ok') {
1.406.2.3 raeburn 9527: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.4 raeburn 9528: $response .= '<span class="LC_warning">'.$instd_chk.'</span><br />';
1.406.2.3 raeburn 9529: if ($domd_chk eq 'ok') {
1.406.2.4 raeburn 9530: $response .= &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.');
1.406.2.3 raeburn 9531: }
1.406.2.5 raeburn 9532: $response .= '<br />';
1.406.2.3 raeburn 9533: }
9534: } else {
9535: unless (($context eq 'requestcrs') && ($srch->{'srchtype'} eq 'exact')) {
9536: my $domd_chk = &domdirectorysrch_check($srch);
1.406.2.14 raeburn 9537: if (($domd_chk ne 'ok') && ($env{'form.action'} ne 'accesslogs')) {
1.406.2.3 raeburn 9538: my $instd_chk = &instdirectorysrch_check($srch);
1.406.2.4 raeburn 9539: $response .= '<span class="LC_warning">'.$domd_chk.'</span><br />';
1.406.2.3 raeburn 9540: if ($instd_chk eq 'ok') {
1.406.2.4 raeburn 9541: $response .= &mt('You may want to search in the institutional directory instead of the LON-CAPA domain.');
1.406.2.3 raeburn 9542: }
1.406.2.5 raeburn 9543: $response .= '<br />';
1.406.2.3 raeburn 9544: }
1.160 raeburn 9545: }
9546: }
9547: if ($response ne '') {
1.180 raeburn 9548: return ($currstate,$response);
1.160 raeburn 9549: }
9550: if ($srch->{'srchby'} eq 'uname') {
9551: if (($srch->{'srchin'} eq 'dom') || ($srch->{'srchin'} eq 'crs')) {
9552: if ($env{'form.forcenew'}) {
9553: if ($srch->{'srchdomain'} ne $env{'request.role.domain'}) {
9554: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9555: if ($uhome eq 'no_host') {
9556: my $domdesc = &Apache::lonnet::domain($env{'request.role.domain'},'description');
1.180 raeburn 9557: my $showdom = &display_domain_info($env{'request.role.domain'});
9558: $response = &mt('New users can only be created in the domain to which your current role belongs - [_1].',$showdom);
1.160 raeburn 9559: } else {
1.179 raeburn 9560: $currstate = 'modify';
1.160 raeburn 9561: }
9562: } else {
1.179 raeburn 9563: $currstate = 'modify';
1.160 raeburn 9564: }
9565: } else {
9566: if ($srch->{'srchin'} eq 'dom') {
1.162 raeburn 9567: if ($srch->{'srchtype'} eq 'exact') {
9568: my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
9569: if ($uhome eq 'no_host') {
1.179 raeburn 9570: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9571: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9572: } else {
1.179 raeburn 9573: $currstate = 'modify';
1.406.2.5 raeburn 9574: if ($env{'form.action'} eq 'accesslogs') {
9575: $currstate = 'activity';
9576: }
1.310 raeburn 9577: my $uname = $srch->{'srchterm'};
9578: my $udom = $srch->{'srchdomain'};
9579: $srch_results{$uname.':'.$udom} =
9580: { &Apache::lonnet::get('environment',
9581: ['firstname',
9582: 'lastname',
9583: 'permanentemail'],
9584: $udom,$uname)
9585: };
1.162 raeburn 9586: }
9587: } else {
9588: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9589: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9590: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9591: }
9592: } else {
1.167 albertel 9593: my $courseusers = &get_courseusers();
1.162 raeburn 9594: if ($srch->{'srchtype'} eq 'exact') {
1.167 albertel 9595: if (exists($courseusers->{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
1.179 raeburn 9596: $currstate = 'modify';
1.162 raeburn 9597: } else {
1.179 raeburn 9598: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9599: &build_search_response($context,$srch,%srch_results);
1.162 raeburn 9600: }
1.160 raeburn 9601: } else {
1.167 albertel 9602: foreach my $user (keys(%$courseusers)) {
1.162 raeburn 9603: my ($cuname,$cudomain) = split(/:/,$user);
9604: if ($cudomain eq $srch->{'srchdomain'}) {
1.177 raeburn 9605: my $matched = 0;
9606: if ($srch->{'srchtype'} eq 'begins') {
9607: if ($cuname =~ /^\Q$srch->{'srchterm'}\E/i) {
9608: $matched = 1;
9609: }
9610: } else {
9611: if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
9612: $matched = 1;
9613: }
9614: }
9615: if ($matched) {
1.167 albertel 9616: $srch_results{$user} =
9617: {&Apache::lonnet::get('environment',
9618: ['firstname',
9619: 'lastname',
1.194 albertel 9620: 'permanentemail'],
9621: $cudomain,$cuname)};
1.162 raeburn 9622: }
9623: }
9624: }
1.179 raeburn 9625: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9626: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9627: }
9628: }
9629: }
9630: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9631: $currstate = 'query';
1.160 raeburn 9632: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9633: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9634: if ($dirsrchres eq 'ok') {
9635: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9636: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9637: } else {
9638: my $showdom = &display_domain_info($srch->{'srchdomain'});
9639: $response = '<span class="LC_warning">'.
9640: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9641: '</span><br />'.
9642: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 9643: '<br />';
1.181 raeburn 9644: }
1.160 raeburn 9645: }
9646: } else {
9647: if ($srch->{'srchin'} eq 'dom') {
9648: %srch_results = &Apache::lonnet::usersearch($srch);
1.179 raeburn 9649: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9650: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9651: } elsif ($srch->{'srchin'} eq 'crs') {
1.167 albertel 9652: my $courseusers = &get_courseusers();
9653: foreach my $user (keys(%$courseusers)) {
1.160 raeburn 9654: my ($uname,$udom) = split(/:/,$user);
9655: my %names = &Apache::loncommon::getnames($uname,$udom);
9656: my %emails = &Apache::loncommon::getemails($uname,$udom);
9657: if ($srch->{'srchby'} eq 'lastname') {
9658: if ((($srch->{'srchtype'} eq 'exact') &&
9659: ($names{'lastname'} eq $srch->{'srchterm'})) ||
1.177 raeburn 9660: (($srch->{'srchtype'} eq 'begins') &&
9661: ($names{'lastname'} =~ /^\Q$srch->{'srchterm'}\E/i)) ||
1.160 raeburn 9662: (($srch->{'srchtype'} eq 'contains') &&
9663: ($names{'lastname'} =~ /\Q$srch->{'srchterm'}\E/i))) {
9664: $srch_results{$user} = {firstname => $names{'firstname'},
9665: lastname => $names{'lastname'},
9666: permanentemail => $emails{'permanentemail'},
9667: };
9668: }
9669: } elsif ($srch->{'srchby'} eq 'lastfirst') {
9670: my ($srchlast,$srchfirst) = split(/,/,$srch->{'srchterm'});
1.177 raeburn 9671: $srchlast =~ s/\s+$//;
9672: $srchfirst =~ s/^\s+//;
1.160 raeburn 9673: if ($srch->{'srchtype'} eq 'exact') {
9674: if (($names{'lastname'} eq $srchlast) &&
9675: ($names{'firstname'} eq $srchfirst)) {
9676: $srch_results{$user} = {firstname => $names{'firstname'},
9677: lastname => $names{'lastname'},
9678: permanentemail => $emails{'permanentemail'},
9679:
9680: };
9681: }
1.177 raeburn 9682: } elsif ($srch->{'srchtype'} eq 'begins') {
9683: if (($names{'lastname'} =~ /^\Q$srchlast\E/i) &&
9684: ($names{'firstname'} =~ /^\Q$srchfirst\E/i)) {
9685: $srch_results{$user} = {firstname => $names{'firstname'},
9686: lastname => $names{'lastname'},
9687: permanentemail => $emails{'permanentemail'},
9688: };
9689: }
9690: } else {
1.160 raeburn 9691: if (($names{'lastname'} =~ /\Q$srchlast\E/i) &&
9692: ($names{'firstname'} =~ /\Q$srchfirst\E/i)) {
9693: $srch_results{$user} = {firstname => $names{'firstname'},
9694: lastname => $names{'lastname'},
9695: permanentemail => $emails{'permanentemail'},
9696: };
9697: }
9698: }
9699: }
9700: }
1.179 raeburn 9701: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9702: &build_search_response($context,$srch,%srch_results);
1.160 raeburn 9703: } elsif ($srch->{'srchin'} eq 'alc') {
1.179 raeburn 9704: $currstate = 'query';
1.160 raeburn 9705: } elsif ($srch->{'srchin'} eq 'instd') {
1.181 raeburn 9706: ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query($srch);
9707: if ($dirsrchres eq 'ok') {
9708: ($currstate,$response,$forcenewuser) =
1.221 raeburn 9709: &build_search_response($context,$srch,%srch_results);
1.181 raeburn 9710: } else {
1.406.2.5 raeburn 9711: my $showdom = &display_domain_info($srch->{'srchdomain'});
9712: $response = '<span class="LC_warning">'.
1.181 raeburn 9713: &mt('Institutional directory search is not available in domain: [_1]',$showdom).
9714: '</span><br />'.
9715: &mt('You may want to search in the LON-CAPA domain instead of the institutional directory.').
1.406.2.5 raeburn 9716: '<br />';
1.181 raeburn 9717: }
1.160 raeburn 9718: }
9719: }
1.179 raeburn 9720: return ($currstate,$response,$forcenewuser,\%srch_results);
1.160 raeburn 9721: }
9722:
1.406.2.3 raeburn 9723: sub domdirectorysrch_check {
9724: my ($srch) = @_;
9725: my $response;
9726: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
9727: ['directorysrch'],$srch->{'srchdomain'});
9728: my $showdom = &display_domain_info($srch->{'srchdomain'});
9729: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
9730: if ($dom_inst_srch{'directorysrch'}{'lcavailable'} eq '0') {
9731: return &mt('LON-CAPA directory search is not available in domain: [_1]',$showdom);
9732: }
9733: if ($dom_inst_srch{'directorysrch'}{'lclocalonly'}) {
9734: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
9735: return &mt('LON-CAPA directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
9736: }
9737: }
9738: }
9739: return 'ok';
9740: }
9741:
9742: sub instdirectorysrch_check {
1.160 raeburn 9743: my ($srch) = @_;
9744: my $can_search = 0;
9745: my $response;
9746: my %dom_inst_srch = &Apache::lonnet::get_dom('configuration',
9747: ['directorysrch'],$srch->{'srchdomain'});
1.180 raeburn 9748: my $showdom = &display_domain_info($srch->{'srchdomain'});
1.160 raeburn 9749: if (ref($dom_inst_srch{'directorysrch'}) eq 'HASH') {
9750: if (!$dom_inst_srch{'directorysrch'}{'available'}) {
1.180 raeburn 9751: return &mt('Institutional directory search is not available in domain: [_1]',$showdom);
1.160 raeburn 9752: }
9753: if ($dom_inst_srch{'directorysrch'}{'localonly'}) {
9754: if ($env{'request.role.domain'} ne $srch->{'srchdomain'}) {
1.180 raeburn 9755: return &mt('Institutional directory search in domain: [_1] is only allowed for users with a current role in the domain.',$showdom);
1.160 raeburn 9756: }
9757: my @usertypes = split(/:/,$env{'environment.inststatus'});
9758: if (!@usertypes) {
9759: push(@usertypes,'default');
9760: }
9761: if (ref($dom_inst_srch{'directorysrch'}{'cansearch'}) eq 'ARRAY') {
9762: foreach my $type (@usertypes) {
9763: if (grep(/^\Q$type\E$/,@{$dom_inst_srch{'directorysrch'}{'cansearch'}})) {
9764: $can_search = 1;
9765: last;
9766: }
9767: }
9768: }
9769: if (!$can_search) {
9770: my ($insttypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($srch->{'srchdomain'});
9771: my @longtypes;
9772: foreach my $item (@usertypes) {
1.229 raeburn 9773: if (defined($insttypes->{$item})) {
9774: push (@longtypes,$insttypes->{$item});
9775: } elsif ($item eq 'default') {
9776: push (@longtypes,&mt('other'));
9777: }
1.160 raeburn 9778: }
9779: my $insttype_str = join(', ',@longtypes);
1.180 raeburn 9780: return &mt('Institutional directory search in domain: [_1] is not available to your user type: ',$showdom).$insttype_str;
1.229 raeburn 9781: }
1.160 raeburn 9782: } else {
9783: $can_search = 1;
9784: }
9785: } else {
1.180 raeburn 9786: return &mt('Institutional directory search has not been configured for domain: [_1]',$showdom);
1.160 raeburn 9787: }
9788: my %longtext = &Apache::lonlocal::texthash (
1.167 albertel 9789: uname => 'username',
1.160 raeburn 9790: lastfirst => 'last name, first name',
1.167 albertel 9791: lastname => 'last name',
1.172 raeburn 9792: contains => 'contains',
1.178 raeburn 9793: exact => 'as exact match to',
9794: begins => 'begins with',
1.160 raeburn 9795: );
9796: if ($can_search) {
9797: if (ref($dom_inst_srch{'directorysrch'}{'searchby'}) eq 'ARRAY') {
9798: if (!grep(/^\Q$srch->{'srchby'}\E$/,@{$dom_inst_srch{'directorysrch'}{'searchby'}})) {
1.180 raeburn 9799: return &mt('Institutional directory search in domain: [_1] is not available for searching by "[_2]"',$showdom,$longtext{$srch->{'srchby'}});
1.160 raeburn 9800: }
9801: } else {
1.180 raeburn 9802: return &mt('Institutional directory search in domain: [_1] is not available.', $showdom);
1.160 raeburn 9803: }
9804: }
9805: if ($can_search) {
1.178 raeburn 9806: if (ref($dom_inst_srch{'directorysrch'}{'searchtypes'}) eq 'ARRAY') {
9807: if (grep(/^\Q$srch->{'srchtype'}\E/,@{$dom_inst_srch{'directorysrch'}{'searchtypes'}})) {
9808: return 'ok';
9809: } else {
1.180 raeburn 9810: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 9811: }
9812: } else {
9813: if ((($dom_inst_srch{'directorysrch'}{'searchtypes'} eq 'specify') &&
9814: ($srch->{'srchtype'} eq 'exact' || $srch->{'srchtype'} eq 'contains')) ||
9815: ($dom_inst_srch{'directorysrch'}{'searchtypes'} eq $srch->{'srchtype'})) {
9816: return 'ok';
9817: } else {
1.180 raeburn 9818: return &mt('Institutional directory search in domain [_1] is not available for the requested search type: "[_2]"',$showdom,$longtext{$srch->{'srchtype'}});
1.178 raeburn 9819: }
1.160 raeburn 9820: }
9821: }
9822: }
9823:
9824: sub get_courseusers {
9825: my %advhash;
1.167 albertel 9826: my $classlist = &Apache::loncoursedata::get_classlist();
1.160 raeburn 9827: my %coursepersonnel=&Apache::lonnet::get_course_adv_roles();
9828: foreach my $role (sort(keys(%coursepersonnel))) {
9829: foreach my $user (split(/\,/,$coursepersonnel{$role})) {
1.167 albertel 9830: if (!exists($classlist->{$user})) {
9831: $classlist->{$user} = [];
9832: }
1.160 raeburn 9833: }
9834: }
1.167 albertel 9835: return $classlist;
1.160 raeburn 9836: }
9837:
9838: sub build_search_response {
1.221 raeburn 9839: my ($context,$srch,%srch_results) = @_;
1.179 raeburn 9840: my ($currstate,$response,$forcenewuser);
1.160 raeburn 9841: my %names = (
1.330 bisitz 9842: 'uname' => 'username',
9843: 'lastname' => 'last name',
1.160 raeburn 9844: 'lastfirst' => 'last name, first name',
1.330 bisitz 9845: 'crs' => 'this course',
9846: 'dom' => 'LON-CAPA domain',
9847: 'instd' => 'the institutional directory for domain',
1.160 raeburn 9848: );
9849:
9850: my %single = (
1.180 raeburn 9851: begins => 'A match',
1.160 raeburn 9852: contains => 'A match',
1.180 raeburn 9853: exact => 'An exact match',
1.160 raeburn 9854: );
9855: my %nomatch = (
1.180 raeburn 9856: begins => 'No match',
1.160 raeburn 9857: contains => 'No match',
1.180 raeburn 9858: exact => 'No exact match',
1.160 raeburn 9859: );
9860: if (keys(%srch_results) > 1) {
1.179 raeburn 9861: $currstate = 'select';
1.160 raeburn 9862: } else {
9863: if (keys(%srch_results) == 1) {
1.406.2.5 raeburn 9864: if ($env{'form.action'} eq 'accesslogs') {
9865: $currstate = 'activity';
9866: } else {
9867: $currstate = 'modify';
9868: }
1.180 raeburn 9869: $response = &mt("$single{$srch->{'srchtype'}} was found for the $names{$srch->{'srchby'}} ([_1]) in $names{$srch->{'srchin'}}.",$srch->{'srchterm'});
9870: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 9871: $response .= ': '.&display_domain_info($srch->{'srchdomain'});
1.180 raeburn 9872: }
1.330 bisitz 9873: } else { # Search has nothing found. Prepare message to user.
9874: $response = '<span class="LC_warning">';
1.180 raeburn 9875: if ($srch->{'srchin'} eq 'dom' || $srch->{'srchin'} eq 'instd') {
1.330 bisitz 9876: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}: [_2]",
9877: '<b>'.$srch->{'srchterm'}.'</b>',
9878: &display_domain_info($srch->{'srchdomain'}));
9879: } else {
9880: $response .= &mt("$nomatch{$srch->{'srchtype'}} found for the $names{$srch->{'srchby'}} [_1] in $names{$srch->{'srchin'}}.",
9881: '<b>'.$srch->{'srchterm'}.'</b>');
1.180 raeburn 9882: }
9883: $response .= '</span>';
1.330 bisitz 9884:
1.160 raeburn 9885: if ($srch->{'srchin'} ne 'alc') {
9886: $forcenewuser = 1;
9887: my $cansrchinst = 0;
1.406.2.14 raeburn 9888: if (($srch->{'srchdomain'}) && ($env{'form.action'} ne 'accesslogs')) {
1.160 raeburn 9889: my %domconfig = &Apache::lonnet::get_dom('configuration',['directorysrch'],$srch->{'srchdomain'});
9890: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
9891: if ($domconfig{'directorysrch'}{'available'}) {
9892: $cansrchinst = 1;
9893: }
9894: }
9895: }
1.180 raeburn 9896: if ((($srch->{'srchby'} eq 'lastfirst') ||
9897: ($srch->{'srchby'} eq 'lastname')) &&
9898: ($srch->{'srchin'} eq 'dom')) {
9899: if ($cansrchinst) {
9900: $response .= '<br />'.&mt('You may want to broaden your search to a search of the institutional directory for the domain.');
1.160 raeburn 9901: }
9902: }
1.180 raeburn 9903: if ($srch->{'srchin'} eq 'crs') {
9904: $response .= '<br />'.&mt('You may want to broaden your search to the selected LON-CAPA domain.');
9905: }
9906: }
1.305 raeburn 9907: my $createdom = $env{'request.role.domain'};
9908: if ($context eq 'requestcrs') {
9909: if ($env{'form.coursedom'} ne '') {
9910: $createdom = $env{'form.coursedom'};
9911: }
9912: }
1.406.2.5 raeburn 9913: unless (($env{'form.action'} eq 'accesslogs') || (($srch->{'srchby'} eq 'uname') && ($srch->{'srchin'} eq 'dom') &&
9914: ($srch->{'srchtype'} eq 'exact') && ($srch->{'srchdomain'} eq $createdom))) {
1.221 raeburn 9915: my $cancreate =
1.305 raeburn 9916: &Apache::lonuserutils::can_create_user($createdom,$context);
9917: my $targetdom = '<span class="LC_cusr_emph">'.$createdom.'</span>';
1.221 raeburn 9918: if ($cancreate) {
1.305 raeburn 9919: my $showdom = &display_domain_info($createdom);
1.266 bisitz 9920: $response .= '<br /><br />'
9921: .'<b>'.&mt('To add a new user:').'</b>'
1.305 raeburn 9922: .'<br />';
9923: if ($context eq 'requestcrs') {
9924: $response .= &mt("(You can only define new users in the new course's domain - [_1])",$targetdom);
9925: } else {
9926: $response .= &mt("(You can only create new users in your current role's domain - [_1])",$targetdom);
9927: }
9928: $response .='<ul><li>'
1.266 bisitz 9929: .&mt("Set 'Domain/institution to search' to: [_1]",'<span class="LC_cusr_emph">'.$showdom.'</span>')
9930: .'</li><li>'
9931: .&mt("Set 'Search criteria' to: [_1]username is ..... in selected LON-CAPA domain[_2]",'<span class="LC_cusr_emph">','</span>')
9932: .'</li><li>'
9933: .&mt('Provide the proposed username')
9934: .'</li><li>'
9935: .&mt("Click 'Search'")
9936: .'</li></ul><br />';
1.221 raeburn 9937: } else {
1.406.2.7 raeburn 9938: unless (($context eq 'domain') && ($env{'form.action'} eq 'singleuser')) {
9939: my $helplink = ' href="javascript:helpMenu('."'display'".')"';
9940: $response .= '<br /><br />';
9941: if ($context eq 'requestcrs') {
9942: $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
9943: } else {
9944: $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
9945: }
9946: $response .= '<br />'
9947: .&mt('Please contact the [_1]helpdesk[_2] if you need to create a new user.'
9948: ,' <a'.$helplink.'>'
9949: ,'</a>')
9950: .'<br />';
1.305 raeburn 9951: }
1.221 raeburn 9952: }
1.160 raeburn 9953: }
9954: }
9955: }
1.179 raeburn 9956: return ($currstate,$response,$forcenewuser);
1.160 raeburn 9957: }
9958:
1.180 raeburn 9959: sub display_domain_info {
9960: my ($dom) = @_;
9961: my $output = $dom;
9962: if ($dom ne '') {
9963: my $domdesc = &Apache::lonnet::domain($dom,'description');
9964: if ($domdesc ne '') {
9965: $output .= ' <span class="LC_cusr_emph">('.$domdesc.')</span>';
9966: }
9967: }
9968: return $output;
9969: }
9970:
1.160 raeburn 9971: sub crumb_utilities {
9972: my %elements = (
9973: crtuser => {
9974: srchterm => 'text',
1.172 raeburn 9975: srchin => 'selectbox',
1.160 raeburn 9976: srchby => 'selectbox',
9977: srchtype => 'selectbox',
9978: srchdomain => 'selectbox',
9979: },
1.207 raeburn 9980: crtusername => {
9981: srchterm => 'text',
9982: srchdomain => 'selectbox',
9983: },
1.160 raeburn 9984: docustom => {
9985: rolename => 'selectbox',
9986: newrolename => 'textbox',
9987: },
1.179 raeburn 9988: studentform => {
9989: srchterm => 'text',
9990: srchin => 'selectbox',
9991: srchby => 'selectbox',
9992: srchtype => 'selectbox',
9993: srchdomain => 'selectbox',
9994: },
1.160 raeburn 9995: );
9996:
9997: my $jsback .= qq|
9998: function backPage(formname,prevphase,prevstate) {
1.211 raeburn 9999: if (typeof prevphase == 'undefined') {
10000: formname.phase.value = '';
10001: }
10002: else {
10003: formname.phase.value = prevphase;
10004: }
10005: if (typeof prevstate == 'undefined') {
10006: formname.currstate.value = '';
10007: }
10008: else {
10009: formname.currstate.value = prevstate;
10010: }
1.160 raeburn 10011: formname.submit();
10012: }
10013: |;
10014: return ($jsback,\%elements);
10015: }
10016:
1.26 matthew 10017: sub course_level_table {
1.375 raeburn 10018: my ($inccourses,$showcredits,$defaultcredits) = @_;
10019: return unless (ref($inccourses) eq 'HASH');
1.26 matthew 10020: my $table = '';
1.62 www 10021: # Custom Roles?
10022:
1.190 raeburn 10023: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.89 raeburn 10024: my %lt=&Apache::lonlocal::texthash(
10025: 'exs' => "Existing sections",
10026: 'new' => "Define new section",
10027: 'ssd' => "Set Start Date",
10028: 'sed' => "Set End Date",
1.131 raeburn 10029: 'crl' => "Course Level",
1.89 raeburn 10030: 'act' => "Activate",
10031: 'rol' => "Role",
10032: 'ext' => "Extent",
1.113 raeburn 10033: 'grs' => "Section",
1.375 raeburn 10034: 'crd' => "Credits",
1.89 raeburn 10035: 'sta' => "Start",
10036: 'end' => "End"
10037: );
1.62 www 10038:
1.375 raeburn 10039: foreach my $protectedcourse (sort(keys(%{$inccourses}))) {
1.135 raeburn 10040: my $thiscourse=$protectedcourse;
1.26 matthew 10041: $thiscourse=~s:_:/:g;
10042: my %coursedata=&Apache::lonnet::coursedescription($thiscourse);
1.365 raeburn 10043: my $isowner = &Apache::lonuserutils::is_courseowner($protectedcourse,$coursedata{'internal.courseowner'});
1.26 matthew 10044: my $area=$coursedata{'description'};
1.321 raeburn 10045: my $crstype=$coursedata{'type'};
1.135 raeburn 10046: if (!defined($area)) { $area=&mt('Unavailable course').': '.$protectedcourse; }
1.89 raeburn 10047: my ($domain,$cnum)=split(/\//,$thiscourse);
1.115 albertel 10048: my %sections_count;
1.101 albertel 10049: if (defined($env{'request.course.id'})) {
10050: if ($env{'request.course.id'} eq $domain.'_'.$cnum) {
1.115 albertel 10051: %sections_count =
10052: &Apache::loncommon::get_sections($domain,$cnum);
1.92 raeburn 10053: }
10054: }
1.321 raeburn 10055: my @roles = &Apache::lonuserutils::roles_by_context('course','',$crstype);
1.213 raeburn 10056: foreach my $role (@roles) {
1.321 raeburn 10057: my $plrole=&Apache::lonnet::plaintext($role,$crstype);
1.329 raeburn 10058: if ((&Apache::lonnet::allowed('c'.$role,$thiscourse)) ||
10059: ((($role eq 'cc') || ($role eq 'co')) && ($isowner))) {
1.221 raeburn 10060: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10061: $plrole,\%sections_count,\%lt,
1.402 raeburn 10062: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10063: } elsif ($env{'request.course.sec'} ne '') {
10064: if (&Apache::lonnet::allowed('c'.$role,$thiscourse.'/'.
10065: $env{'request.course.sec'})) {
10066: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.375 raeburn 10067: $plrole,\%sections_count,\%lt,
1.402 raeburn 10068: $showcredits,$defaultcredits,$crstype);
1.26 matthew 10069: }
10070: }
10071: }
1.221 raeburn 10072: if (&Apache::lonnet::allowed('ccr',$thiscourse)) {
1.324 raeburn 10073: foreach my $cust (sort(keys(%customroles))) {
10074: next if ($crstype eq 'Community' && $customroles{$cust} =~ /bre\&S/);
1.221 raeburn 10075: my $role = 'cr_cr_'.$env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cust;
10076: $table .= &course_level_row($protectedcourse,$role,$area,$domain,
1.402 raeburn 10077: $cust,\%sections_count,\%lt,
10078: $showcredits,$defaultcredits,$crstype);
1.221 raeburn 10079: }
1.62 www 10080: }
1.26 matthew 10081: }
10082: return '' if ($table eq ''); # return nothing if there is nothing
10083: # in the table
1.188 raeburn 10084: my $result;
10085: if (!$env{'request.course.id'}) {
10086: $result = '<h4>'.$lt{'crl'}.'</h4>'."\n";
10087: }
10088: $result .=
1.136 raeburn 10089: &Apache::loncommon::start_data_table().
10090: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10091: '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.402 raeburn 10092: '<th>'.$lt{'ext'}.'</th><th>'."\n";
10093: if ($showcredits) {
10094: $result .= $lt{'crd'}.'</th>';
10095: }
10096: $result .=
1.375 raeburn 10097: '<th>'.$lt{'grs'}.'</th><th>'.$lt{'sta'}.'</th>'."\n".
10098: '<th>'.$lt{'end'}.'</th>'.
1.136 raeburn 10099: &Apache::loncommon::end_data_table_header_row().
10100: $table.
10101: &Apache::loncommon::end_data_table();
1.26 matthew 10102: return $result;
10103: }
1.88 raeburn 10104:
1.221 raeburn 10105: sub course_level_row {
1.375 raeburn 10106: my ($protectedcourse,$role,$area,$domain,$plrole,$sections_count,
1.402 raeburn 10107: $lt,$showcredits,$defaultcredits,$crstype) = @_;
1.375 raeburn 10108: my $creditem;
1.222 raeburn 10109: my $row = &Apache::loncommon::start_data_table_row().
10110: ' <td><input type="checkbox" name="act_'.
10111: $protectedcourse.'_'.$role.'" /></td>'."\n".
10112: ' <td>'.$plrole.'</td>'."\n".
10113: ' <td>'.$area.'<br />Domain: '.$domain.'</td>'."\n";
1.402 raeburn 10114: if (($showcredits) && ($role eq 'st') && ($crstype eq 'Course')) {
1.375 raeburn 10115: $row .=
10116: '<td><input type="text" name="credits_'.$protectedcourse.'_'.
10117: $role.'" size="3" value="'.$defaultcredits.'" /></td>';
10118: } else {
10119: $row .= '<td> </td>';
10120: }
1.322 raeburn 10121: if (($role eq 'cc') || ($role eq 'co')) {
1.222 raeburn 10122: $row .= '<td> </td>';
1.221 raeburn 10123: } elsif ($env{'request.course.sec'} ne '') {
1.222 raeburn 10124: $row .= ' <td><input type="hidden" value="'.
10125: $env{'request.course.sec'}.'" '.
10126: 'name="sec_'.$protectedcourse.'_'.$role.'" />'.
10127: $env{'request.course.sec'}.'</td>';
1.221 raeburn 10128: } else {
10129: if (ref($sections_count) eq 'HASH') {
10130: my $currsec =
10131: &Apache::lonuserutils::course_sections($sections_count,
10132: $protectedcourse.'_'.$role);
1.222 raeburn 10133: $row .= '<td><table class="LC_createuser">'."\n".
10134: '<tr class="LC_section_row">'."\n".
10135: ' <td valign="top">'.$lt->{'exs'}.'<br />'.
10136: $currsec.'</td>'."\n".
10137: ' <td> </td>'."\n".
10138: ' <td valign="top"> '.$lt->{'new'}.'<br />'.
1.221 raeburn 10139: '<input type="text" name="newsec_'.$protectedcourse.'_'.$role.
10140: '" value="" />'.
10141: '<input type="hidden" '.
10142: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n".
1.222 raeburn 10143: '</tr></table></td>'."\n";
1.221 raeburn 10144: } else {
1.222 raeburn 10145: $row .= '<td><input type="text" size="10" '.
1.375 raeburn 10146: 'name="sec_'.$protectedcourse.'_'.$role.'" /></td>'."\n";
1.221 raeburn 10147: }
10148: }
1.222 raeburn 10149: $row .= <<ENDTIMEENTRY;
10150: <td><input type="hidden" name="start_$protectedcourse\_$role" value="" />
1.221 raeburn 10151: <a href=
10152: "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 10153: <td><input type="hidden" name="end_$protectedcourse\_$role" value="" />
1.221 raeburn 10154: <a href=
10155: "javascript:pjump('date_end','End Date $plrole',document.cu.end_$protectedcourse\_$role.value,'end_$protectedcourse\_$role','cu.pres','dateset')">$lt->{'sed'}</a></td>
10156: ENDTIMEENTRY
1.222 raeburn 10157: $row .= &Apache::loncommon::end_data_table_row();
10158: return $row;
1.221 raeburn 10159: }
10160:
1.88 raeburn 10161: sub course_level_dc {
1.375 raeburn 10162: my ($dcdom,$showcredits) = @_;
1.190 raeburn 10163: my %customroles=&Apache::lonuserutils::my_custom_roles();
1.213 raeburn 10164: my @roles = &Apache::lonuserutils::roles_by_context('course');
1.88 raeburn 10165: my $hiddenitems = '<input type="hidden" name="dcdomain" value="'.$dcdom.'" />'.
10166: '<input type="hidden" name="origdom" value="'.$dcdom.'" />'.
1.133 raeburn 10167: '<input type="hidden" name="dccourse" value="" />';
1.355 www 10168: my $courseform=&Apache::loncommon::selectcourse_link
1.356 raeburn 10169: ('cu','dccourse','dcdomain','coursedesc',undef,undef,'Select','crstype');
1.375 raeburn 10170: my $credit_elem;
10171: if ($showcredits) {
10172: $credit_elem = 'credits';
10173: }
10174: my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($dcdom,'currsec','cu','role','Course/Community Browser',$credit_elem);
1.88 raeburn 10175: my %lt=&Apache::lonlocal::texthash(
10176: 'rol' => "Role",
1.113 raeburn 10177: 'grs' => "Section",
1.88 raeburn 10178: 'exs' => "Existing sections",
10179: 'new' => "Define new section",
10180: 'sta' => "Start",
10181: 'end' => "End",
10182: 'ssd' => "Set Start Date",
1.355 www 10183: 'sed' => "Set End Date",
1.375 raeburn 10184: 'scc' => "Course/Community",
10185: 'crd' => "Credits",
1.88 raeburn 10186: );
1.323 raeburn 10187: my $header = '<h4>'.&mt('Course/Community Level').'</h4>'.
1.136 raeburn 10188: &Apache::loncommon::start_data_table().
10189: &Apache::loncommon::start_data_table_header_row().
1.375 raeburn 10190: '<th>'.$lt{'scc'}.'</th><th>'.$lt{'rol'}.'</th>'."\n".
1.397 bisitz 10191: '<th>'.$lt{'grs'}.'</th>'."\n";
10192: $header .= '<th>'.$lt{'crd'}.'</th>'."\n" if ($showcredits);
10193: $header .= '<th>'.$lt{'sta'}.'</th><th>'.$lt{'end'}.'</th>'."\n".
1.136 raeburn 10194: &Apache::loncommon::end_data_table_header_row();
1.143 raeburn 10195: my $otheritems = &Apache::loncommon::start_data_table_row()."\n".
1.356 raeburn 10196: '<td><br /><span class="LC_nobreak"><input type="text" name="coursedesc" value="" onfocus="this.blur();opencrsbrowser('."'cu','dccourse','dcdomain','coursedesc','','','','crstype'".')" />'.
10197: $courseform.(' ' x4).'</span></td>'."\n".
1.389 bisitz 10198: '<td valign="top"><br /><select name="role">'."\n";
1.213 raeburn 10199: foreach my $role (@roles) {
1.135 raeburn 10200: my $plrole=&Apache::lonnet::plaintext($role);
1.389 bisitz 10201: $otheritems .= ' <option value="'.$role.'">'.$plrole.'</option>';
1.88 raeburn 10202: }
1.404 raeburn 10203: if ( keys(%customroles) > 0) {
10204: foreach my $cust (sort(keys(%customroles))) {
1.101 albertel 10205: my $custrole='cr_cr_'.$env{'user.domain'}.
1.135 raeburn 10206: '_'.$env{'user.name'}.'_'.$cust;
1.389 bisitz 10207: $otheritems .= ' <option value="'.$custrole.'">'.$cust.'</option>';
1.88 raeburn 10208: }
10209: }
10210: $otheritems .= '</select></td><td>'.
10211: '<table border="0" cellspacing="0" cellpadding="0">'.
10212: '<tr><td valign="top"><b>'.$lt{'exs'}.'</b><br /><select name="currsec">'.
1.389 bisitz 10213: ' <option value=""><--'.&mt('Pick course first').'</option></select></td>'.
1.88 raeburn 10214: '<td> </td>'.
10215: '<td valign="top"> <b>'.$lt{'new'}.'</b><br />'.
1.113 raeburn 10216: '<input type="text" name="newsec" value="" />'.
1.237 raeburn 10217: '<input type="hidden" name="section" value="" />'.
1.323 raeburn 10218: '<input type="hidden" name="groups" value="" />'.
10219: '<input type="hidden" name="crstype" value="" /></td>'.
1.375 raeburn 10220: '</tr></table></td>'."\n";
10221: if ($showcredits) {
10222: $otheritems .= '<td><br />'."\n".
1.397 bisitz 10223: '<input type="text" size="3" name="credits" value="" /></td>'."\n";
1.375 raeburn 10224: }
1.88 raeburn 10225: $otheritems .= <<ENDTIMEENTRY;
1.323 raeburn 10226: <td><br /><input type="hidden" name="start" value='' />
1.88 raeburn 10227: <a href=
10228: "javascript:pjump('date_start','Start Date',document.cu.start.value,'start','cu.pres','dateset')">$lt{'ssd'}</a></td>
1.323 raeburn 10229: <td><br /><input type="hidden" name="end" value='' />
1.88 raeburn 10230: <a href=
10231: "javascript:pjump('date_end','End Date',document.cu.end.value,'end','cu.pres','dateset')">$lt{'sed'}</a></td>
10232: ENDTIMEENTRY
1.136 raeburn 10233: $otheritems .= &Apache::loncommon::end_data_table_row().
10234: &Apache::loncommon::end_data_table()."\n";
1.406.2.20.2. (raeburn 10235:): return $cb_jscript.$hiddenitems.$header.$otheritems;
1.88 raeburn 10236: }
10237:
1.237 raeburn 10238: sub update_selfenroll_config {
1.400 raeburn 10239: my ($r,$cid,$cdom,$cnum,$context,$crstype,$currsettings) = @_;
1.398 raeburn 10240: return unless (ref($currsettings) eq 'HASH');
10241: my ($row,$lt) = &Apache::lonuserutils::get_selfenroll_titles();
10242: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.237 raeburn 10243: my (%changes,%warning);
1.241 raeburn 10244: my $curr_types;
1.400 raeburn 10245: my %noedit;
10246: unless ($context eq 'domain') {
10247: %noedit = &get_noedit_fields($cdom,$cnum,$crstype,$row);
10248: }
1.237 raeburn 10249: if (ref($row) eq 'ARRAY') {
10250: foreach my $item (@{$row}) {
1.400 raeburn 10251: next if ($noedit{$item});
1.237 raeburn 10252: if ($item eq 'enroll_dates') {
10253: my (%currenrolldate,%newenrolldate);
10254: foreach my $type ('start','end') {
1.398 raeburn 10255: $currenrolldate{$type} = $currsettings->{'selfenroll_'.$type.'_date'};
1.237 raeburn 10256: $newenrolldate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_date');
10257: if ($newenrolldate{$type} ne $currenrolldate{$type}) {
10258: $changes{'internal.selfenroll_'.$type.'_date'} = $newenrolldate{$type};
10259: }
10260: }
10261: } elsif ($item eq 'access_dates') {
10262: my (%currdate,%newdate);
10263: foreach my $type ('start','end') {
1.398 raeburn 10264: $currdate{$type} = $currsettings->{'selfenroll_'.$type.'_access'};
1.237 raeburn 10265: $newdate{$type} = &Apache::lonhtmlcommon::get_date_from_form('selfenroll_'.$type.'_access');
10266: if ($newdate{$type} ne $currdate{$type}) {
10267: $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
10268: }
10269: }
1.241 raeburn 10270: } elsif ($item eq 'types') {
1.398 raeburn 10271: $curr_types = $currsettings->{'selfenroll_'.$item};
1.241 raeburn 10272: if ($env{'form.selfenroll_all'}) {
10273: if ($curr_types ne '*') {
10274: $changes{'internal.selfenroll_types'} = '*';
10275: } else {
10276: next;
10277: }
10278: } else {
1.249 raeburn 10279: my %currdoms;
1.241 raeburn 10280: my @entries = split(/;/,$curr_types);
10281: my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
1.249 raeburn 10282: my @activations = &Apache::loncommon::get_env_multiple('form.selfenroll_activate');
1.241 raeburn 10283: my $newnum = 0;
1.249 raeburn 10284: my @latesttypes;
10285: foreach my $num (@activations) {
10286: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$num);
10287: if (@types > 0) {
1.241 raeburn 10288: @types = sort(@types);
10289: my $typestr = join(',',@types);
1.249 raeburn 10290: my $typedom = $env{'form.selfenroll_dom_'.$num};
10291: $latesttypes[$newnum] = $typedom.':'.$typestr;
10292: $currdoms{$typedom} = 1;
1.241 raeburn 10293: $newnum ++;
10294: }
10295: }
1.338 raeburn 10296: for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
10297: if ((!grep(/^$j$/,@deletedoms)) && (!grep(/^$j$/,@activations))) {
1.249 raeburn 10298: my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
10299: if (@types > 0) {
10300: @types = sort(@types);
10301: my $typestr = join(',',@types);
10302: my $typedom = $env{'form.selfenroll_dom_'.$j};
10303: $latesttypes[$newnum] = $typedom.':'.$typestr;
10304: $currdoms{$typedom} = 1;
10305: $newnum ++;
10306: }
10307: }
10308: }
10309: if ($env{'form.selfenroll_newdom'} ne '') {
10310: my $typedom = $env{'form.selfenroll_newdom'};
10311: if ((!defined($currdoms{$typedom})) &&
10312: (&Apache::lonnet::domain($typedom) ne '')) {
10313: my $typestr;
10314: my ($othertitle,$usertypes,$types) =
10315: &Apache::loncommon::sorted_inst_types($typedom);
10316: my $othervalue = 'any';
10317: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
10318: if (@{$types} > 0) {
1.257 raeburn 10319: my @esc_types = map { &escape($_); } @{$types};
1.249 raeburn 10320: $othervalue = 'other';
1.258 raeburn 10321: $typestr = join(',',(@esc_types,$othervalue));
1.249 raeburn 10322: }
10323: $typestr = $othervalue;
10324: } else {
10325: $typestr = $othervalue;
10326: }
10327: $latesttypes[$newnum] = $typedom.':'.$typestr;
10328: $newnum ++ ;
10329: }
10330: }
1.241 raeburn 10331: my $selfenroll_types = join(';',@latesttypes);
10332: if ($selfenroll_types ne $curr_types) {
10333: $changes{'internal.selfenroll_types'} = $selfenroll_types;
10334: }
10335: }
1.276 raeburn 10336: } elsif ($item eq 'limit') {
10337: my $newlimit = $env{'form.selfenroll_limit'};
10338: my $newcap = $env{'form.selfenroll_cap'};
10339: $newcap =~s/\s+//g;
1.398 raeburn 10340: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10341: $currlimit = 'none' if ($currlimit eq '');
1.398 raeburn 10342: my $currcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10343: if ($newlimit ne $currlimit) {
10344: if ($newlimit ne 'none') {
10345: if ($newcap =~ /^\d+$/) {
10346: if ($newcap ne $currcap) {
10347: $changes{'internal.selfenroll_cap'} = $newcap;
10348: }
10349: $changes{'internal.selfenroll_limit'} = $newlimit;
10350: } else {
1.398 raeburn 10351: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10352: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10353: }
10354: } elsif ($currcap ne '') {
10355: $changes{'internal.selfenroll_cap'} = '';
10356: $changes{'internal.selfenroll_limit'} = $newlimit;
10357: }
10358: } elsif ($currlimit ne 'none') {
10359: if ($newcap =~ /^\d+$/) {
10360: if ($newcap ne $currcap) {
10361: $changes{'internal.selfenroll_cap'} = $newcap;
10362: }
10363: } else {
1.398 raeburn 10364: $warning{$item} = &mt('Maximum enrollment setting unchanged.').'<br />'.
10365: &mt('The value provided was invalid - it must be a positive integer if enrollment is being limited.');
1.276 raeburn 10366: }
10367: }
10368: } elsif ($item eq 'approval') {
10369: my (@currnotified,@newnotified);
1.398 raeburn 10370: my $currapproval = $currsettings->{'selfenroll_approval'};
10371: my $currnotifylist = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10372: if ($currnotifylist ne '') {
10373: @currnotified = split(/,/,$currnotifylist);
10374: @currnotified = sort(@currnotified);
10375: }
10376: my $newapproval = $env{'form.selfenroll_approval'};
10377: @newnotified = &Apache::loncommon::get_env_multiple('form.selfenroll_notify');
10378: @newnotified = sort(@newnotified);
10379: if ($newapproval ne $currapproval) {
10380: $changes{'internal.selfenroll_approval'} = $newapproval;
10381: if (!$newapproval) {
10382: if ($currnotifylist ne '') {
10383: $changes{'internal.selfenroll_notifylist'} = '';
10384: }
10385: } else {
10386: my @differences =
1.295 raeburn 10387: &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10388: if (@differences > 0) {
10389: if (@newnotified > 0) {
10390: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10391: } else {
10392: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10393: }
10394: }
10395: }
10396: } else {
1.295 raeburn 10397: my @differences = &Apache::loncommon::compare_arrays(\@currnotified,\@newnotified);
1.276 raeburn 10398: if (@differences > 0) {
10399: if (@newnotified > 0) {
10400: $changes{'internal.selfenroll_notifylist'} = join(',',@newnotified);
10401: } else {
10402: $changes{'internal.selfenroll_notifylist'} = '';
10403: }
10404: }
10405: }
1.237 raeburn 10406: } else {
1.398 raeburn 10407: my $curr_val = $currsettings->{'selfenroll_'.$item};
1.237 raeburn 10408: my $newval = $env{'form.selfenroll_'.$item};
10409: if ($item eq 'section') {
10410: $newval = $env{'form.sections'};
1.241 raeburn 10411: if (defined($curr_groups{$newval})) {
1.237 raeburn 10412: $newval = $curr_val;
1.398 raeburn 10413: $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.
10414: &mt('Group names and section names must be distinct');
1.237 raeburn 10415: } elsif ($newval eq 'all') {
10416: $newval = $curr_val;
1.274 bisitz 10417: $warning{$item} = &mt('Section for self-enrolled users unchanged, as "all" is a reserved section name.');
1.237 raeburn 10418: }
10419: if ($newval eq '') {
10420: $newval = 'none';
10421: }
10422: }
10423: if ($newval ne $curr_val) {
10424: $changes{'internal.selfenroll_'.$item} = $newval;
10425: }
1.241 raeburn 10426: }
1.237 raeburn 10427: }
10428: if (keys(%warning) > 0) {
10429: foreach my $item (@{$row}) {
10430: if (exists($warning{$item})) {
10431: $r->print($warning{$item}.'<br />');
10432: }
10433: }
10434: }
10435: if (keys(%changes) > 0) {
10436: my $putresult = &Apache::lonnet::put('environment',\%changes,$cdom,$cnum);
10437: if ($putresult eq 'ok') {
10438: if ((exists($changes{'internal.selfenroll_types'})) ||
10439: (exists($changes{'internal.selfenroll_start_date'})) ||
10440: (exists($changes{'internal.selfenroll_end_date'}))) {
10441: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
10442: $cnum,undef,undef,'Course');
10443: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1.398 raeburn 10444: if (ref($crsinfo{$cid}) eq 'HASH') {
1.237 raeburn 10445: foreach my $item ('selfenroll_types','selfenroll_start_date','selfenroll_end_date') {
10446: if (exists($changes{'internal.'.$item})) {
1.398 raeburn 10447: $crsinfo{$cid}{$item} = $changes{'internal.'.$item};
1.237 raeburn 10448: }
10449: }
10450: my $crsputresult =
10451: &Apache::lonnet::courseidput($cdom,\%crsinfo,
10452: $chome,'notime');
10453: }
10454: }
10455: $r->print(&mt('The following changes were made to self-enrollment settings:').'<ul>');
10456: foreach my $item (@{$row}) {
10457: my $title = $item;
10458: if (ref($lt) eq 'HASH') {
10459: $title = $lt->{$item};
10460: }
10461: if ($item eq 'enroll_dates') {
10462: foreach my $type ('start','end') {
10463: if (exists($changes{'internal.selfenroll_'.$type.'_date'})) {
10464: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_date'});
1.244 bisitz 10465: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10466: $title,$type,$newdate).'</li>');
10467: }
10468: }
10469: } elsif ($item eq 'access_dates') {
10470: foreach my $type ('start','end') {
10471: if (exists($changes{'internal.selfenroll_'.$type.'_access'})) {
10472: my $newdate = &Apache::lonlocal::locallocaltime($changes{'internal.selfenroll_'.$type.'_access'});
1.244 bisitz 10473: $r->print('<li>'.&mt('[_1]: "[_2]" set to "[_3]".',
1.237 raeburn 10474: $title,$type,$newdate).'</li>');
10475: }
10476: }
1.276 raeburn 10477: } elsif ($item eq 'limit') {
10478: if ((exists($changes{'internal.selfenroll_limit'})) ||
10479: (exists($changes{'internal.selfenroll_cap'}))) {
10480: my ($newval,$newcap);
10481: if ($changes{'internal.selfenroll_cap'} ne '') {
10482: $newcap = $changes{'internal.selfenroll_cap'}
10483: } else {
1.398 raeburn 10484: $newcap = $currsettings->{'selfenroll_cap'};
1.276 raeburn 10485: }
10486: if ($changes{'internal.selfenroll_limit'} eq 'none') {
10487: $newval = &mt('No limit');
10488: } elsif ($changes{'internal.selfenroll_limit'} eq
10489: 'allstudents') {
10490: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10491: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
10492: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
10493: } else {
1.398 raeburn 10494: my $currlimit = $currsettings->{'selfenroll_limit'};
1.276 raeburn 10495: if ($currlimit eq 'allstudents') {
10496: $newval = &mt('New self-enrollment no longer allowed when total (all students) reaches [_1].',$newcap);
10497: } elsif ($changes{'internal.selfenroll_limit'} eq 'selfenrolled') {
1.308 raeburn 10498: $newval = &mt('New self-enrollment no longer allowed when total number of self-enrolled students reaches [_1].',$newcap);
1.276 raeburn 10499: }
10500: }
10501: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
10502: }
10503: } elsif ($item eq 'approval') {
10504: if ((exists($changes{'internal.selfenroll_approval'})) ||
10505: (exists($changes{'internal.selfenroll_notifylist'}))) {
1.398 raeburn 10506: my %selfdescs = &Apache::lonuserutils::selfenroll_default_descs();
1.276 raeburn 10507: my ($newval,$newnotify);
10508: if (exists($changes{'internal.selfenroll_notifylist'})) {
10509: $newnotify = $changes{'internal.selfenroll_notifylist'};
10510: } else {
1.398 raeburn 10511: $newnotify = $currsettings->{'selfenroll_notifylist'};
1.276 raeburn 10512: }
1.398 raeburn 10513: if (exists($changes{'internal.selfenroll_approval'})) {
10514: if ($changes{'internal.selfenroll_approval'} !~ /^[012]$/) {
10515: $changes{'internal.selfenroll_approval'} = '0';
10516: }
10517: $newval = $selfdescs{'approval'}{$changes{'internal.selfenroll_approval'}};
1.276 raeburn 10518: } else {
1.398 raeburn 10519: my $currapproval = $currsettings->{'selfenroll_approval'};
10520: if ($currapproval !~ /^[012]$/) {
10521: $currapproval = 0;
1.276 raeburn 10522: }
1.398 raeburn 10523: $newval = $selfdescs{'approval'}{$currapproval};
1.276 raeburn 10524: }
10525: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval));
10526: if ($newnotify) {
1.277 raeburn 10527: $r->print('<br />'.&mt('The following will be notified when an enrollment request needs approval, or has been approved: [_1].',$newnotify));
1.276 raeburn 10528: } else {
1.277 raeburn 10529: $r->print('<br />'.&mt('No notifications sent when an enrollment request needs approval, or has been approved.'));
1.276 raeburn 10530: }
10531: $r->print('</li>'."\n");
10532: }
1.237 raeburn 10533: } else {
10534: if (exists($changes{'internal.selfenroll_'.$item})) {
1.241 raeburn 10535: my $newval = $changes{'internal.selfenroll_'.$item};
10536: if ($item eq 'types') {
10537: if ($newval eq '') {
10538: $newval = &mt('None');
10539: } elsif ($newval eq '*') {
10540: $newval = &mt('Any user in any domain');
10541: }
1.245 raeburn 10542: } elsif ($item eq 'registered') {
10543: if ($newval eq '1') {
10544: $newval = &mt('Yes');
10545: } elsif ($newval eq '0') {
10546: $newval = &mt('No');
10547: }
1.241 raeburn 10548: }
1.244 bisitz 10549: $r->print('<li>'.&mt('"[_1]" set to "[_2]".',$title,$newval).'</li>'."\n");
1.237 raeburn 10550: }
10551: }
10552: }
10553: $r->print('</ul>');
1.398 raeburn 10554: if ($env{'course.'.$cid.'.description'} ne '') {
10555: my %newenvhash;
10556: foreach my $key (keys(%changes)) {
10557: $newenvhash{'course.'.$cid.'.'.$key} = $changes{$key};
10558: }
10559: &Apache::lonnet::appenv(\%newenvhash);
1.237 raeburn 10560: }
10561: } else {
1.398 raeburn 10562: $r->print(&mt('An error occurred when saving changes to self-enrollment settings in this course.').'<br />'.
10563: &mt('The error was: [_1].',$putresult));
1.237 raeburn 10564: }
10565: } else {
1.249 raeburn 10566: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.237 raeburn 10567: }
10568: } else {
1.249 raeburn 10569: $r->print(&mt('No changes were made to the existing self-enrollment settings in this course.'));
1.241 raeburn 10570: }
1.406.2.20.2. (raeburn 10571:): my $visactions = &cat_visibility($cdom);
1.400 raeburn 10572: my ($cathash,%cattype);
10573: my %domconfig = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
10574: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
10575: $cathash = $domconfig{'coursecategories'}{'cats'};
10576: $cattype{'auth'} = $domconfig{'coursecategories'}{'auth'};
10577: $cattype{'unauth'} = $domconfig{'coursecategories'}{'unauth'};
10578: } else {
10579: $cathash = {};
10580: $cattype{'auth'} = 'std';
10581: $cattype{'unauth'} = 'std';
10582: }
10583: if (($cattype{'auth'} eq 'none') && ($cattype{'unauth'} eq 'none')) {
10584: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10585: '<br />'.
10586: '<br />'.$visactions->{'take'}.'<ul>'.
10587: '<li>'.$visactions->{'dc_chgconf'}.'</li>'.
10588: '</ul>');
10589: } elsif (($cattype{'auth'} !~ /^(std|domonly)$/) && ($cattype{'unauth'} !~ /^(std|domonly)$/)) {
10590: if ($currsettings->{'uniquecode'}) {
10591: $r->print('<span class="LC_info">'.$visactions->{'vis'}.'</span>');
10592: } else {
1.366 bisitz 10593: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
1.400 raeburn 10594: '<br />'.
10595: '<br />'.$visactions->{'take'}.'<ul>'.
10596: '<li>'.$visactions->{'dc_setcode'}.'</li>'.
10597: '</ul><br />');
10598: }
10599: } else {
10600: my ($visible,$cansetvis,$vismsgs) = &visible_in_stdcat($cdom,$cnum,\%domconfig);
10601: if (ref($visactions) eq 'HASH') {
10602: if (!$visible) {
10603: $r->print('<br /><span class="LC_warning">'.$visactions->{'miss'}.'</span><br />'.$visactions->{'yous'}.
10604: '<br />');
10605: if (ref($vismsgs) eq 'ARRAY') {
10606: $r->print('<br />'.$visactions->{'take'}.'<ul>');
10607: foreach my $item (@{$vismsgs}) {
10608: $r->print('<li>'.$visactions->{$item}.'</li>');
10609: }
10610: $r->print('</ul>');
1.256 raeburn 10611: }
1.400 raeburn 10612: $r->print($cansetvis);
1.256 raeburn 10613: }
10614: }
10615: }
1.237 raeburn 10616: return;
10617: }
10618:
1.27 matthew 10619: #---------------------------------------------- end functions for &phase_two
1.29 matthew 10620:
10621: #--------------------------------- functions for &phase_two and &phase_three
10622:
10623: #--------------------------end of functions for &phase_two and &phase_three
1.372 raeburn 10624:
1.1 www 10625: 1;
10626: __END__
1.2 www 10627:
10628:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>