Annotation of loncom/interface/lonmodifycourse.pm, revision 1.91
1.20 albertel 1: # The LearningOnline Network with CAPA
1.28 raeburn 2: # handler for DC-only modifiable course settings
1.20 albertel 3: #
1.91 ! raeburn 4: # $Id: lonmodifycourse.pm,v 1.90 2017/01/05 16:17:11 raeburn Exp $
1.20 albertel 5: #
1.3 raeburn 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.1 raeburn 28: package Apache::lonmodifycourse;
29:
30: use strict;
31: use Apache::Constants qw(:common :http);
32: use Apache::lonnet;
33: use Apache::loncommon;
1.28 raeburn 34: use Apache::lonhtmlcommon;
1.1 raeburn 35: use Apache::lonlocal;
1.36 raeburn 36: use Apache::lonuserutils;
1.72 raeburn 37: use Apache::loncreateuser;
1.28 raeburn 38: use Apache::lonpickcourse;
1.1 raeburn 39: use lib '/home/httpd/lib/perl';
1.72 raeburn 40: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 41:
1.28 raeburn 42: sub get_dc_settable {
1.60 raeburn 43: my ($type,$cdom) = @_;
1.83 raeburn 44: if ($type eq 'Community') {
1.72 raeburn 45: return ('courseowner','selfenrollmgrdc','selfenrollmgrcc');
1.48 raeburn 46: } else {
1.85 raeburn 47: my @items = ('courseowner','coursecode','authtype','autharg','selfenrollmgrdc',
48: 'selfenrollmgrcc','mysqltables');
1.60 raeburn 49: if (&showcredits($cdom)) {
50: push(@items,'defaultcredits');
51: }
52: return @items;
1.48 raeburn 53: }
54: }
55:
56: sub autoenroll_keys {
1.60 raeburn 57: my $internals = ['coursecode','courseowner','authtype','autharg','defaultcredits',
58: 'autoadds','autodrops','autostart','autoend','sectionnums',
1.84 raeburn 59: 'crosslistings','co-owners','autodropfailsafe'];
1.48 raeburn 60: my $accessdates = ['default_enrollment_start_date','default_enrollment_end_date'];
61: return ($internals,$accessdates);
1.28 raeburn 62: }
63:
1.38 raeburn 64: sub catalog_settable {
1.49 raeburn 65: my ($confhash,$type) = @_;
1.38 raeburn 66: my @settable;
67: if (ref($confhash) eq 'HASH') {
1.49 raeburn 68: if ($type eq 'Community') {
69: if ($confhash->{'togglecatscomm'} ne 'comm') {
70: push(@settable,'togglecats');
71: }
72: if ($confhash->{'categorizecomm'} ne 'comm') {
73: push(@settable,'categorize');
74: }
1.81 raeburn 75: } elsif ($type eq 'Placement') {
76: if ($confhash->{'togglecatsplace'} ne 'place') {
77: push(@settable,'togglecats');
78: }
79: if ($confhash->{'categorizeplace'} ne 'place') {
80: push(@settable,'categorize');
81: }
1.49 raeburn 82: } else {
83: if ($confhash->{'togglecats'} ne 'crs') {
84: push(@settable,'togglecats');
85: }
86: if ($confhash->{'categorize'} ne 'crs') {
87: push(@settable,'categorize');
88: }
1.38 raeburn 89: }
90: } else {
91: push(@settable,('togglecats','categorize'));
92: }
93: return @settable;
94: }
95:
1.28 raeburn 96: sub get_enrollment_settings {
97: my ($cdom,$cnum) = @_;
1.48 raeburn 98: my ($internals,$accessdates) = &autoenroll_keys();
99: my @items;
100: if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
101: @items = map { 'internal.'.$_; } (@{$internals});
102: push(@items,@{$accessdates});
103: }
104: my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
1.28 raeburn 105: my %enrollvar;
106: $enrollvar{'autharg'} = '';
107: $enrollvar{'authtype'} = '';
1.48 raeburn 108: foreach my $item (keys(%settings)) {
1.28 raeburn 109: if ($item =~ m/^internal\.(.+)$/) {
110: my $type = $1;
111: if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
112: if ($settings{$item} == 1) {
113: $enrollvar{$type} = "ON";
114: } else {
115: $enrollvar{$type} = "OFF";
1.10 raeburn 116: }
1.28 raeburn 117: } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
118: if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
1.48 raeburn 119: $enrollvar{$type} = &mt('No end date');
1.28 raeburn 120: } else {
1.48 raeburn 121: $enrollvar{$type} = &Apache::lonlocal::locallocaltime($settings{$item});
1.14 raeburn 122: }
1.50 raeburn 123: } elsif (($type eq 'sectionnums') || ($type eq 'co-owners')) {
1.28 raeburn 124: $enrollvar{$type} = $settings{$item};
125: $enrollvar{$type} =~ s/,/, /g;
126: } elsif ($type eq "authtype"
127: || $type eq "autharg" || $type eq "coursecode"
1.84 raeburn 128: || $type eq "crosslistings" || $type eq "selfenrollmgr"
129: || $type eq "autodropfailsafe") {
1.28 raeburn 130: $enrollvar{$type} = $settings{$item};
1.60 raeburn 131: } elsif ($type eq 'defaultcredits') {
132: if (&showcredits($cdom)) {
133: $enrollvar{$type} = $settings{$item};
134: }
1.28 raeburn 135: } elsif ($type eq 'courseowner') {
136: if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
137: $enrollvar{$type} = $settings{$item};
138: } else {
139: if ($settings{$item} ne '') {
140: $enrollvar{$type} = $settings{$item}.':'.$cdom;
1.26 raeburn 141: }
1.1 raeburn 142: }
1.28 raeburn 143: }
144: } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
145: my $type = $1;
146: if ( ($type eq 'end') && ($settings{$item} == 0) ) {
1.48 raeburn 147: $enrollvar{$item} = &mt('No end date');
1.28 raeburn 148: } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
149: $enrollvar{$item} = 'When enrolled';
150: } else {
1.48 raeburn 151: $enrollvar{$item} = &Apache::lonlocal::locallocaltime($settings{$item});
1.1 raeburn 152: }
153: }
154: }
1.28 raeburn 155: return %enrollvar;
156: }
157:
158: sub print_course_search_page {
159: my ($r,$dom,$domdesc) = @_;
1.48 raeburn 160: my $action = '/adm/modifycourse';
161: my $type = $env{'form.type'};
162: if (!defined($env{'form.type'})) {
163: $type = 'Course';
164: }
165: &print_header($r,$type);
1.70 raeburn 166: my ($filterlist,$filter) = &get_filters($dom);
1.56 raeburn 167: my ($numtitles,$cctitle,$dctitle,@codetitles);
1.48 raeburn 168: my $ccrole = 'cc';
169: if ($type eq 'Community') {
170: $ccrole = 'co';
1.46 raeburn 171: }
1.48 raeburn 172: $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.46 raeburn 173: $dctitle = &Apache::lonnet::plaintext('dc');
1.70 raeburn 174: $r->print(&Apache::loncommon::js_changer());
1.48 raeburn 175: if ($type eq 'Community') {
176: $r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
1.81 raeburn 177: } elsif ($type eq 'Placement') {
178: $r->print('<h3>'.&mt('Search for a placement test in the [_1] domain',$domdesc).'</h3>');
1.48 raeburn 179: } else {
180: $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
1.69 raeburn 181: }
182: $r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
183: \$numtitles,'modifycourse',undef,undef,undef,
1.70 raeburn 184: \@codetitles,$dom));
1.87 raeburn 185:
1.86 raeburn 186: my ($actiontext,$roleoption,$settingsoption);
1.48 raeburn 187: if ($type eq 'Community') {
1.86 raeburn 188: $actiontext = &mt('Actions available after searching for a community:');
1.81 raeburn 189: } elsif ($type eq 'Placement') {
1.86 raeburn 190: $actiontext = &mt('Actions available after searching for a placement test:')
191: } else {
192: $actiontext = &mt('Actions available after searching for a course:');
1.48 raeburn 193: }
1.86 raeburn 194: if (&Apache::lonnet::allowed('ccc',$dom)) {
195: if ($type eq 'Community') {
196: $roleoption = &mt('Enter the community with the role of [_1]',$cctitle);
197: $settingsoption = &mt('View or modify community settings which only a [_1] may modify.',$dctitle);
198: } elsif ($type eq 'Placement') {
199: $roleoption = &mt('Enter the placement test with the role of [_1]',$cctitle);
200: $settingsoption = &mt('View or modify placement test settings which only a [_1] may modify.',$dctitle);
201: } else {
202: $roleoption = &mt('Enter the course with the role of [_1]',$cctitle);
203: $settingsoption = &mt('View or modify course settings which only a [_1] may modify.',$dctitle);
204: }
205: } elsif (&Apache::lonnet::allowed('rar',$dom)) {
1.90 raeburn 206: my ($roles_by_num,$description,$accessref,$accessinfo) = &Apache::lonnet::get_all_adhocroles($dom);
207: if ((ref($roles_by_num) eq 'ARRAY') && (ref($description) eq 'HASH')) {
208: if (@{$roles_by_num} > 1) {
1.86 raeburn 209: if ($type eq 'Community') {
1.90 raeburn 210: $roleoption = &mt('Enter the community with one of the available ad hoc roles');
1.86 raeburn 211: } elsif ($type eq 'Placement') {
1.90 raeburn 212: $roleoption = &mt('Enter the placement test with one of the available ad hoc roles.');
1.86 raeburn 213: } else {
1.90 raeburn 214: $roleoption = &mt('Enter the course with one of the available ad hoc roles.');
1.86 raeburn 215: }
216: } else {
1.90 raeburn 217: my $rolename = $description->{$roles_by_num->[0]};
1.86 raeburn 218: if ($type eq 'Community') {
1.90 raeburn 219: $roleoption = &mt('Enter the community with the ad hoc role of: [_1]',$rolename);
1.86 raeburn 220: } elsif ($type eq 'Placement') {
1.90 raeburn 221: $roleoption = &mt('Enter the placement test with the ad hoc role of: [_1]',$rolename);
1.86 raeburn 222: } else {
1.90 raeburn 223: $roleoption = &mt('Enter the course with the ad hoc role of: [_1]',$rolename);
1.86 raeburn 224: }
225: }
226: }
227: if ($type eq 'Community') {
228: $settingsoption = &mt('View community settings which only a [_1] may modify.',$dctitle);
229: } elsif ($type eq 'Placement') {
230: $settingsoption = &mt('View placement test settings which only a [_1] may modify.',$dctitle);
231: } else {
232: $settingsoption = &mt('View course settings which only a [_1] may modify.',$dctitle);
233: }
234: }
235: $r->print($actiontext.'<ul>');
236: if ($roleoption) {
237: $r->print('<li>'.$roleoption.'</li>'."\n");
238: }
239: $r->print('<li>'.$settingsoption.'</li>'."\n".'</ul>');
1.69 raeburn 240: return;
1.28 raeburn 241: }
242:
243: sub print_course_selection_page {
1.90 raeburn 244: my ($r,$dom,$domdesc,$permission) = @_;
1.48 raeburn 245: my $type = $env{'form.type'};
246: if (!defined($type)) {
247: $type = 'Course';
248: }
249: &print_header($r,$type);
1.28 raeburn 250:
1.90 raeburn 251: if ($permission->{'adhocrole'} eq 'custom') {
252: my %lt = &Apache::lonlocal::texthash(
253: title => 'Ad hoc role selection',
254: preamble => 'Please choose an ad hoc role in the course.',
255: cancel => 'Click "OK" to enter the course, or "Cancel" to choose a different course.',
256: );
257: my %jslt = &Apache::lonlocal::texthash (
258: none => 'You are not eligible to use an ad hoc role for the selected course',
259: ok => 'OK',
260: exit => 'Cancel',
261: );
262: &js_escape(\%jslt);
263: $r->print(<<"END");
264: <script type="text/javascript">
265: // <![CDATA[
266: \$(document).ready(function(){
267: \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
268: });
269:
270: function gochoose(cname,cdom,cdesc) {
271: document.courselist.pickedcourse.value = cdom+'_'+cname;
272: \$("#LC_choose_adhoc").empty();
273: var pickedaction = \$('input[name=phase]:checked', '#LCcoursepicker').val();
274: if (pickedaction == 'adhocrole') {
275: var http = new XMLHttpRequest();
276: var url = "/adm/pickcourse";
277: var params = "cid="+cdom+"_"+cname+"&context=adhoc";
278: http.open("POST", url, true);
279: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
280: http.onreadystatechange = function() {
281: if (http.readyState == 4 && http.status == 200) {
282: var data = \$.parseJSON(http.responseText);
283: var len = data.roles.length;
284: if (len == '' || len == null || len == 0) {
285: alert('$jslt{none}');
286: } else {
287: if (len == 1) {
288: \$( '[name="adhocrole"]' )[0].value = data.roles[0].name;
289: document.courselist.submit();
290: } else {
291: var str = '';
292: for (var i=0; i<data.roles.length; i++) {
293: \$("<label><input type='radio' value='"+data.roles[i].name+"' name='LC_get_role' id='LC_get_role_"+i+"' />"+data.roles[i].desc+"</label><span> </span>")
294: .appendTo("#LC_choose_adhoc");
295: }
296: \$( "#LC_get_role_0").prop("checked", true);
297: \$( "#LC_adhocrole_chooser" ).dialog({ autoOpen: false });
298: \$( "#LC_adhocrole_chooser" ).dialog("open");
299: \$( "#LC_adhocrole_chooser" ).dialog({
300: height: 400,
301: width: 500,
302: modal: true,
303: resizable: false,
304: buttons: [
305: {
306: text: "$jslt{'ok'}",
307: click: function() {
308: var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val();
309: \$( '[name="adhocrole"]' )[0].value = rolename;
310: document.courselist.submit();
311: }
312: },
313: {
314: text: "$jslt{'exit'}",
315: click: function() {
316: \$("#LC_adhocrole_chooser").dialog( "close" );
317: }
318: }
319: ],
320: });
321: \$( "#LC_adhocrole_chooser" ).find( "form" ).on( "submit", function( event ) {
322: event.preventDefault();
323: var rolename = \$('input[name=LC_get_role]:checked', '#LChelpdeskpicker').val()
324: \$( '[name="adhocrole"]' )[0].value = rolename;
325: document.courselist.submit();
326: \$("#LC_adhocrole_chooser").dialog( "close" );
327: });
328: }
329: }
330: }
331: }
332: http.send(params);
333: } else {
334: document.courselist.submit();
335: }
336: return;
337: }
338: // ]]>
339: </script>
340:
341: <div id="LC_adhocrole_chooser" title="$lt{'title'}">
342: <p>$lt{'preamble'}</p>
343: <form name="LChelpdeskadhoc" id="LChelpdeskpicker" action="">
344: <div id="LC_choose_adhoc">
345: </div>
346: <input type="hidden" name="adhocrole" id="LCadhocrole" value="" />
347: <input type="submit" tabindex="-1" style="position:absolute; top:-1000px" />
348: </form>
349: <p>$lt{'cancel'}</p>
350: </div>
351: END
352: } elsif ($permission->{'adhocrole'} eq 'coord') {
353: $r->print(<<"END");
354: <script type="text/javascript">
355: // <![CDATA[
356:
357: function gochoose(cname,cdom,cdesc) {
358: document.courselist.pickedcourse.value = cdom+'_'+cname;
359: document.courselist.submit();
360: return;
361: }
362:
363: // ]]>
364: </script>
365: END
366: }
367:
368: # Criteria for course search
1.69 raeburn 369: my ($filterlist,$filter) = &get_filters();
1.28 raeburn 370: my $action = '/adm/modifycourse';
371: my $dctitle = &Apache::lonnet::plaintext('dc');
1.56 raeburn 372: my ($numtitles,@codetitles);
1.70 raeburn 373: $r->print(&Apache::loncommon::js_changer());
1.48 raeburn 374: $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
1.69 raeburn 375: $r->print(&Apache::loncommon::build_filters($filterlist,$type,undef,undef,$filter,$action,
376: \$numtitles,'modifycourse',undef,undef,undef,
1.70 raeburn 377: \@codetitles,$dom,$env{'form.form'}));
378: my %courses = &Apache::loncommon::search_courses($dom,$type,$filter,$numtitles,
379: undef,undef,undef,\@codetitles);
1.46 raeburn 380: &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
1.86 raeburn 381: $dom,undef,%courses);
1.1 raeburn 382: return;
383: }
384:
1.69 raeburn 385: sub get_filters {
1.70 raeburn 386: my ($dom) = @_;
1.69 raeburn 387: my @filterlist = ('descriptfilter','instcodefilter','ownerfilter',
388: 'ownerdomfilter','coursefilter','sincefilter');
389: # created filter
1.70 raeburn 390: my $loncaparev = &Apache::lonnet::get_server_loncaparev($dom);
1.69 raeburn 391: if ($loncaparev ne 'unknown_cmd') {
392: push(@filterlist,'createdfilter');
393: }
394: my %filter;
395: foreach my $item (@filterlist) {
396: $filter{$item} = $env{'form.'.$item};
397: }
398: return (\@filterlist,\%filter);
399: }
400:
1.28 raeburn 401: sub print_modification_menu {
1.86 raeburn 402: my ($r,$cdesc,$domdesc,$dom,$type,$cid,$coursehash,$permission) = @_;
1.48 raeburn 403: &print_header($r,$type);
1.88 raeburn 404: my ($ccrole,$categorytitle,$setquota_text,$setuploadquota_text,$cdom,$cnum);
1.71 raeburn 405: if (ref($coursehash) eq 'HASH') {
406: $cdom = $coursehash->{'domain'};
407: $cnum = $coursehash->{'num'};
408: } else {
409: ($cdom,$cnum) = split(/_/,$cid);
410: }
1.48 raeburn 411: if ($type eq 'Community') {
412: $ccrole = 'co';
413: } else {
414: $ccrole = 'cc';
1.61 raeburn 415: }
1.88 raeburn 416: my %linktext;
417: if ($permission->{'setparms'} eq 'edit') {
418: %linktext = (
419: 'setquota' => 'View/Modify quotas for group portfolio files, and for uploaded content',
420: 'setanon' => 'View/Modify responders threshold for anonymous survey submissions display',
421: 'selfenroll' => 'View/Modify Self-Enrollment configuration',
422: 'setpostsubmit' => 'View/Modify submit button behavior, post-submission',
423: );
424: } else {
425: %linktext = (
426: 'setquota' => 'View quotas for group portfolio files, and for uploaded content',
427: 'setanon' => 'View responders threshold for anonymous survey submissions display',
428: 'selfenroll' => 'View Self-Enrollment configuration',
429: 'setpostsubmit' => 'View submit button behavior, post-submission',
430: );
431: }
1.48 raeburn 432: if ($type eq 'Community') {
1.88 raeburn 433: if ($permission->{'setparms'} eq 'edit') {
434: $categorytitle = 'View/Modify Community Settings';
435: $linktext{'setparms'} = 'View/Modify community owner';
436: $linktext{'catsettings'} = 'View/Modify catalog settings for community';
437: } else {
438: $categorytitle = 'View Community Settings';
439: $linktext{'setparms'} = 'View community owner';
440: $linktext{'catsettings'} = 'View catalog settings for community';
441: }
1.48 raeburn 442: $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
1.61 raeburn 443: $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.');
1.48 raeburn 444: } else {
1.88 raeburn 445: if ($permission->{'setparms'} eq 'edit') {
446: $categorytitle = 'View/Modify Course Settings';
447: $linktext{'catsettings'} = 'View/Modify catalog settings for course';
448: if (($type ne 'Placement') && (&showcredits($dom))) {
449: $linktext{'setparms'} = 'View/Modify course owner, institutional code, default authentication, credits, self-enrollment and table lifetime';
450: } else {
451: $linktext{'setparms'} = 'View/Modify course owner, institutional code, default authentication, self-enrollment and table lifetime';
452: }
453: } else {
454: $categorytitle = 'View Course Settings';
455: $linktext{'catsettings'} = 'View catalog settings for course';
456: if (($type ne 'Placement') && (&showcredits($dom))) {
457: $linktext{'setparms'} = 'View course owner, institutional code, default authentication, credits, self-enrollment and table lifetime';
458: } else {
459: $linktext{'setparms'} = 'View course owner, institutional code, default authentication, self-enrollment and table lifetime';
460: }
461: }
1.48 raeburn 462: $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
1.61 raeburn 463: $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a course via Content Editor.');
1.48 raeburn 464: }
1.75 raeburn 465: my $anon_text = &mt('Responder threshold required to display anonymous survey submissions.');
466: my $postsubmit_text = &mt('Override defaults for submit button behavior post-submission for this specific course.');
1.85 raeburn 467: my $mysqltables_text = &mt('Override default for lifetime of "temporary" MySQL tables containing student performance data.');
1.88 raeburn 468: $linktext{'viewparms'} = 'Display current settings for automated enrollment';
1.54 bisitz 469:
1.38 raeburn 470: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
1.49 raeburn 471: my @additional_params = &catalog_settable($domconf{'coursecategories'},$type);
1.54 bisitz 472:
1.72 raeburn 473: sub manage_selfenrollment {
1.86 raeburn 474: my ($cdom,$cnum,$type,$coursehash,$permission) = @_;
475: if ($permission->{'selfenroll'}) {
476: my ($managed_by_cc,$managed_by_dc) = &Apache::lonuserutils::selfenrollment_administration($cdom,$cnum,$type,$coursehash);
477: if (ref($managed_by_dc) eq 'ARRAY') {
478: if (@{$managed_by_dc}) {
479: return 1;
1.87 raeburn 480: }
1.86 raeburn 481: }
1.72 raeburn 482: }
483: return 0;
484: }
485:
1.54 bisitz 486: sub phaseurl {
487: my $phase = shift;
488: return "javascript:changePage(document.menu,'$phase')"
1.38 raeburn 489: }
1.54 bisitz 490: my @menu =
491: ({ categorytitle => $categorytitle,
492: items => [
493: {
1.88 raeburn 494: linktext => $linktext{'setparms'},
1.54 bisitz 495: url => &phaseurl('setparms'),
1.86 raeburn 496: permission => $permission->{'setparms'},
1.54 bisitz 497: #help => '',
1.55 bisitz 498: icon => 'crsconf.png',
1.54 bisitz 499: linktitle => ''
500: },
501: {
1.88 raeburn 502: linktext => $linktext{'setquota'},
1.54 bisitz 503: url => &phaseurl('setquota'),
1.86 raeburn 504: permission => $permission->{'setquota'},
1.54 bisitz 505: #help => '',
1.55 bisitz 506: icon => 'groupportfolioquota.png',
1.54 bisitz 507: linktitle => ''
508: },
509: {
1.88 raeburn 510: linktext => $linktext{'setanon'},
1.57 raeburn 511: url => &phaseurl('setanon'),
1.86 raeburn 512: permission => $permission->{'setanon'},
1.57 raeburn 513: #help => '',
514: icon => 'anonsurveythreshold.png',
515: linktitle => ''
516: },
517: {
1.88 raeburn 518: linktext => $linktext{'catsettings'},
1.54 bisitz 519: url => &phaseurl('catsettings'),
1.86 raeburn 520: permission => (($permission->{'catsettings'}) && (@additional_params > 0)),
1.54 bisitz 521: #help => '',
1.55 bisitz 522: icon => 'ccatconf.png',
1.54 bisitz 523: linktitle => ''
524: },
525: {
1.88 raeburn 526: linktext => $linktext{'viewparms'},
1.54 bisitz 527: url => &phaseurl('viewparms'),
1.86 raeburn 528: permission => ($permission->{'viewparms'} && ($type ne 'Community') && ($type ne 'Placement')),
1.54 bisitz 529: #help => '',
1.55 bisitz 530: icon => 'roles.png',
1.54 bisitz 531: linktitle => ''
532: },
1.72 raeburn 533: {
1.89 raeburn 534: linktext => $linktext{'selfenroll'},
1.72 raeburn 535: icon => 'self_enroll.png',
536: #help => 'Course_Self_Enrollment',
537: url => &phaseurl('selfenroll'),
1.86 raeburn 538: permission => &manage_selfenrollment($cdom,$cnum,$type,$coursehash,$permission),
1.72 raeburn 539: linktitle => 'Configure user self-enrollment.',
540: },
1.75 raeburn 541: {
1.88 raeburn 542: linktext => $linktext{'setpostsubmit'},
1.75 raeburn 543: icon => 'emblem-readonly.png',
544: #help => '',
545: url => &phaseurl('setpostsubmit'),
1.86 raeburn 546: permission => $permission->{'setpostsubmit'},
1.75 raeburn 547: linktitle => '',
548: },
1.54 bisitz 549: ]
550: },
1.48 raeburn 551: );
1.54 bisitz 552:
553: my $menu_html =
554: '<h3>'
555: .&mt('View/Modify settings for: [_1]',
556: '<span class="LC_nobreak">'.$cdesc.'</span>')
557: .'</h3>'."\n".'<p>';
1.48 raeburn 558: if ($type eq 'Community') {
559: $menu_html .= &mt('Although almost all community settings can be modified by a Coordinator, the following may only be set or modified by a Domain Coordinator:');
560: } else {
561: $menu_html .= &mt('Although almost all course settings can be modified by a Course Coordinator, the following may only be set or modified by a Domain Coordinator:');
562: }
1.54 bisitz 563: $menu_html .= '</p>'."\n".'<ul>';
1.48 raeburn 564: if ($type eq 'Community') {
1.72 raeburn 565: $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>'."\n".
566: '<li>'.&mt('Override defaults for who configures self-enrollment for this specific community').'</li>'."\n";
1.48 raeburn 567: } else {
1.72 raeburn 568: $menu_html .= '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'."\n".
569: '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>'."\n";
1.81 raeburn 570: if (($type ne 'Placement') && &showcredits($dom)) {
1.72 raeburn 571: $menu_html .= '<li>'.&mt('Default credits earned by student on course completion.').'</li>'."\n";
1.60 raeburn 572: }
1.72 raeburn 573: $menu_html .= ' <li>'.&mt('Override defaults for who configures self-enrollment for this specific course.').'</li>'."\n";
1.48 raeburn 574: }
1.85 raeburn 575: $menu_html .= '<li>'.$mysqltables_text.'</li>'."\n".
576: '<li>'.$setquota_text.'</li>'."\n".
1.72 raeburn 577: '<li>'.$setuploadquota_text.'</li>'."\n".
1.75 raeburn 578: '<li>'.$anon_text.'</li>'."\n".
579: '<li>'.$postsubmit_text.'</li>'."\n";
1.86 raeburn 580: my ($categories_link_start,$categories_link_end);
1.88 raeburn 581: if ($permission->{'catsettings'} eq 'edit') {
1.86 raeburn 582: $categories_link_start = '<a href="/adm/domainprefs?actions=coursecategories&phase=display">';
583: $categories_link_end = '</a>';
584: }
1.38 raeburn 585: foreach my $item (@additional_params) {
1.48 raeburn 586: if ($type eq 'Community') {
587: if ($item eq 'togglecats') {
1.86 raeburn 588: $menu_html .= ' <li>'.&mt('Hiding/unhiding a community from the catalog (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).',$categories_link_start,$categories_link_end).'</li>'."\n";
1.48 raeburn 589: } elsif ($item eq 'categorize') {
1.86 raeburn 590: $menu_html .= ' <li>'.&mt('Manual cataloging of a community (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).',$categories_link_start,$categories_link_end).'</li>'."\n";
1.48 raeburn 591: }
592: } else {
593: if ($item eq 'togglecats') {
1.86 raeburn 594: $menu_html .= ' <li>'.&mt('Hiding/unhiding a course from the course catalog (although can be [_1]configured[_2] to be modifiable by a Course Coordinator in course context).',$categories_link_start,$categories_link_end).'</li>'."\n";
1.48 raeburn 595: } elsif ($item eq 'categorize') {
1.86 raeburn 596: $menu_html .= ' <li>'.&mt('Manual cataloging of a course (although can be [_1]configured[_2] to be modifiable by a Course Coordinator in course context).',$categories_link_start,$categories_link_end).'</li>'."\n";
1.48 raeburn 597: }
1.38 raeburn 598: }
599: }
1.54 bisitz 600: $menu_html .=
601: ' </ul>'
602: .'<form name="menu" method="post" action="/adm/modifycourse">'
603: ."\n"
604: .&hidden_form_elements();
1.28 raeburn 605:
606: $r->print($menu_html);
1.54 bisitz 607: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
608: $r->print('</form>');
1.28 raeburn 609: return;
610: }
611:
1.86 raeburn 612: sub print_adhocrole_selected {
1.90 raeburn 613: my ($r,$type,$permission) = @_;
1.48 raeburn 614: &print_header($r,$type);
1.37 raeburn 615: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
1.86 raeburn 616: my ($newrole,$selectrole);
1.90 raeburn 617: if ($permission->{'adhocrole'} eq 'coord') {
1.86 raeburn 618: if ($type eq 'Community') {
619: $newrole = "co./$cdom/$cnum";
620: } else {
621: $newrole = "cc./$cdom/$cnum";
622: }
623: $selectrole = 1;
1.90 raeburn 624: } elsif ($permission->{'adhocrole'} eq 'custom') {
625: my ($okroles,$description) = &Apache::lonnet::get_my_adhocroles($env{'form.pickedcourse'},1);
626: if (ref($okroles) eq 'ARRAY') {
627: my $possrole = $env{'form.adhocrole'};
628: if (($possrole ne '') && (grep(/^\Q$possrole\E$/,@{$okroles}))) {
629: my $confname = &Apache::lonnet::get_domainconfiguser($cdom);
630: $newrole = "cr/$cdom/$confname/$possrole./$cdom/$cnum";
631: $selectrole = 1;
1.86 raeburn 632: }
633: }
634: }
635: if ($selectrole) {
636: $r->print('<form name="adhocrole" method="post" action="/adm/roles">
637: <input type="hidden" name="selectrole" value="'.$selectrole.'" />
638: <input type="hidden" name="newrole" value="'.$newrole.'" />
1.37 raeburn 639: </form>');
1.86 raeburn 640: } else {
641: $r->print('<form name="ccrole" method="post" action="/adm/modifycourse">'.
642: '</form>');
643: }
644: return;
1.37 raeburn 645: }
646:
1.28 raeburn 647: sub print_settings_display {
1.86 raeburn 648: my ($r,$cdom,$cnum,$cdesc,$type,$permission) = @_;
1.28 raeburn 649: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.48 raeburn 650: my %longtype = &course_settings_descrip($type);
1.28 raeburn 651: my %lt = &Apache::lonlocal::texthash(
1.48 raeburn 652: 'valu' => 'Current value',
653: 'cour' => 'Current settings are:',
654: 'cose' => "Settings which control auto-enrollment using classlists from your institution's student information system fall into two groups:",
655: 'dcon' => 'Modifiable only by Domain Coordinator',
656: 'back' => 'Pick another action',
1.28 raeburn 657: );
1.48 raeburn 658: my $ccrole = 'cc';
659: if ($type eq 'Community') {
660: $ccrole = 'co';
661: }
662: my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.28 raeburn 663: my $dctitle = &Apache::lonnet::plaintext('dc');
1.60 raeburn 664: my @modifiable_params = &get_dc_settable($type,$cdom);
1.48 raeburn 665: my ($internals,$accessdates) = &autoenroll_keys();
666: my @items;
667: if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
668: @items = (@{$internals},@{$accessdates});
669: }
1.28 raeburn 670: my $disp_table = &Apache::loncommon::start_data_table()."\n".
671: &Apache::loncommon::start_data_table_header_row()."\n".
1.48 raeburn 672: "<th> </th>\n".
1.28 raeburn 673: "<th>$lt{'valu'}</th>\n".
674: "<th>$lt{'dcon'}</th>\n".
675: &Apache::loncommon::end_data_table_header_row()."\n";
1.48 raeburn 676: foreach my $item (@items) {
1.28 raeburn 677: $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
1.48 raeburn 678: "<td><b>$longtype{$item}</b></td>\n".
679: "<td>$enrollvar{$item}</td>\n";
680: if (grep(/^\Q$item\E$/,@modifiable_params)) {
1.50 raeburn 681: $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n";
1.28 raeburn 682: } else {
1.48 raeburn 683: $disp_table .= '<td align="right">'.&mt('No').'</td>'."\n";
1.28 raeburn 684: }
685: $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
1.3 raeburn 686: }
1.28 raeburn 687: $disp_table .= &Apache::loncommon::end_data_table()."\n";
1.48 raeburn 688: &print_header($r,$type);
1.86 raeburn 689: my ($enroll_link_start,$enroll_link_end,$setparms_link_start,$setparms_link_end);
690: if (&Apache::lonnet::allowed('ccc',$cdom)) {
691: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
692: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
693: '=1&destinationurl=/adm/populate','&<>"');
694: $enroll_link_start = '<a href="'.$escuri.'">';
695: $enroll_link_end = '</a>';
696: }
697: if ($permission->{'setparms'}) {
698: $setparms_link_start = '<a href="javascript:changePage(document.viewparms,'."'setparms'".');">';
699: $setparms_link_end = '</a>';
700: }
1.48 raeburn 701: $r->print('<h3>'.&mt('Current automated enrollment settings for:').
702: ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'.
703: '<form action="/adm/modifycourse" method="post" name="viewparms">'."\n".
704: '<p>'.$lt{'cose'}.'<ul>'.
1.86 raeburn 705: '<li>'.&mt('Settings modifiable by a [_1] via the [_2]Automated Enrollment Manager[_3] in a course.',
706: $cctitle,$enroll_link_start,$enroll_link_end).'</li>');
1.60 raeburn 707: if (&showcredits($cdom)) {
1.86 raeburn 708: $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, default authentication, credits, and self-enrollment[_3].',$dctitle,$setparms_link_start,$setparms_link_end)."\n");
1.60 raeburn 709: } else {
1.86 raeburn 710: $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, default authentication, and self-enrollment[_3].',$dctitle,$setparms_link_start,$setparms_link_end)."\n");
1.60 raeburn 711: }
712: $r->print('</li></ul></p>'.
1.48 raeburn 713: '<p>'.$lt{'cour'}.'</p><p>'.$disp_table.'</p><p>'.
714: '<a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>'."\n".
715: &hidden_form_elements().
716: '</p></form>'
1.86 raeburn 717: );
1.28 raeburn 718: }
1.3 raeburn 719:
1.28 raeburn 720: sub print_setquota {
1.88 raeburn 721: my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
1.61 raeburn 722: my $lctype = lc($type);
723: my $headline = &mt("Set disk space quotas for $lctype: [_1]",
724: '<span class="LC_nobreak">'.$cdesc.'</span>');
1.28 raeburn 725: my %lt = &Apache::lonlocal::texthash(
1.61 raeburn 726: 'gpqu' => 'Disk space for storage of group portfolio files',
727: 'upqu' => 'Disk space for storage of content directly uploaded to course via Content Editor',
1.42 schafran 728: 'modi' => 'Save',
1.48 raeburn 729: 'back' => 'Pick another action',
1.28 raeburn 730: );
1.61 raeburn 731: my %staticdefaults = (
732: coursequota => 20,
733: uploadquota => 500,
734: );
1.68 raeburn 735: my %settings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota','internal.coursecode'],
1.61 raeburn 736: $cdom,$cnum);
1.28 raeburn 737: my $coursequota = $settings{'internal.coursequota'};
1.61 raeburn 738: my $uploadquota = $settings{'internal.uploadquota'};
1.28 raeburn 739: if ($coursequota eq '') {
1.61 raeburn 740: $coursequota = $staticdefaults{'coursequota'};
741: }
742: if ($uploadquota eq '') {
743: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1.72 raeburn 744: my $quotatype = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$type,\%settings);
745: $uploadquota = $domdefs{$quotatype.'quota'};
1.61 raeburn 746: if ($uploadquota eq '') {
747: $uploadquota = $staticdefaults{'uploadquota'};
748: }
1.3 raeburn 749: }
1.48 raeburn 750: &print_header($r,$type);
1.28 raeburn 751: my $hidden_elements = &hidden_form_elements();
1.61 raeburn 752: my $porthelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
753: my $uploadhelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Upload_Quota');
1.88 raeburn 754: my ($disabled,$submit);
755: if ($readonly) {
756: $disabled = ' disabled="disabled"';
757: } else {
758: $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
759: }
1.28 raeburn 760: $r->print(<<ENDDOCUMENT);
1.57 raeburn 761: <form action="/adm/modifycourse" method="post" name="setquota" onsubmit="return verify_quota();">
1.61 raeburn 762: <h3>$headline</h3>
763: <p><span class="LC_nobreak">
1.88 raeburn 764: $porthelpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" $disabled /> MB
1.61 raeburn 765: </span>
766: <br />
767: <span class="LC_nobreak">
1.88 raeburn 768: $uploadhelpitem $lt{'upqu'}: <input type="text" size="4" name="uploadquota" value="$uploadquota" $disabled /> MB
1.61 raeburn 769: </span>
770: </p>
1.28 raeburn 771: <p>
1.88 raeburn 772: $submit
1.28 raeburn 773: </p>
774: $hidden_elements
775: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
776: </form>
777: ENDDOCUMENT
778: return;
779: }
1.3 raeburn 780:
1.57 raeburn 781: sub print_set_anonsurvey_threshold {
1.88 raeburn 782: my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
1.57 raeburn 783: my %lt = &Apache::lonlocal::texthash(
784: 'resp' => 'Responder threshold for anonymous survey submissions display:',
785: 'sufa' => 'Anonymous survey submissions displayed when responders exceeds',
786: 'modi' => 'Save',
787: 'back' => 'Pick another action',
788: );
789: my %settings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
790: my $threshold = $settings{'internal.anonsurvey_threshold'};
791: if ($threshold eq '') {
792: my %domconfig =
793: &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
794: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
795: $threshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
796: if ($threshold eq '') {
797: $threshold = 10;
798: }
799: } else {
800: $threshold = 10;
801: }
802: }
803: &print_header($r,$type);
804: my $hidden_elements = &hidden_form_elements();
1.88 raeburn 805: my ($disabled,$submit);
806: if ($readonly) {
807: $disabled = ' disabled="disabled"';
808: } else {
809: $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
810: }
1.57 raeburn 811: my $helpitem = &Apache::loncommon::help_open_topic('Modify_Anonsurvey_Threshold');
812: $r->print(<<ENDDOCUMENT);
813: <form action="/adm/modifycourse" method="post" name="setanon" onsubmit="return verify_anon_threshold();">
814: <h3>$lt{'resp'} <span class="LC_nobreak">$cdesc</span></h3>
815: <p>
1.88 raeburn 816: $helpitem $lt{'sufa'}: <input type="text" size="4" name="threshold" value="$threshold" $disabled />
817: $submit
1.57 raeburn 818: </p>
819: $hidden_elements
820: <a href="javascript:changePage(document.setanon,'menu')">$lt{'back'}</a>
821: </form>
822: ENDDOCUMENT
823: return;
824: }
825:
1.75 raeburn 826: sub print_postsubmit_config {
1.88 raeburn 827: my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
1.75 raeburn 828: my %lt = &Apache::lonlocal::texthash (
829: 'conf' => 'Configure submit button behavior after student makes a submission',
830: 'disa' => 'Disable submit button/keypress following student submission',
831: 'nums' => 'Number of seconds submit is disabled',
832: 'modi' => 'Save',
833: 'back' => 'Pick another action',
834: 'yes' => 'Yes',
835: 'no' => 'No',
836: );
837: my %settings = &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout',
838: 'internal.coursecode','internal.textbook'],$cdom,$cnum);
839: my $postsubmit = $settings{'internal.postsubmit'};
840: if ($postsubmit eq '') {
841: my %domconfig =
842: &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
843: $postsubmit = 1;
844: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
845: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
846: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
847: $postsubmit = 0;
848: }
849: }
850: }
851: }
852: my ($checkedon,$checkedoff,$display);
853: if ($postsubmit) {
854: $checkedon = 'checked="checked"';
855: $display = 'block';
856: } else {
857: $checkedoff = 'checked="checked"';
858: $display = 'none';
859: }
860: my $postsubtimeout = $settings{'internal.postsubtimeout'};
861: my $default = &domain_postsubtimeout($cdom,$type,\%settings);
862: my $zero = &mt('(Enter 0 to disable until next page reload, or leave blank to use the domain default: [_1])',$default);
863: if ($postsubtimeout eq '') {
864: $postsubtimeout = $default;
865: }
866: &print_header($r,$type);
867: my $hidden_elements = &hidden_form_elements();
1.88 raeburn 868: my ($disabled,$submit);
869: if ($readonly) {
870: $disabled = ' disabled="disabled"';
871: } else {
872: $submit = '<input type="submit" value="'.$lt{'modi'}.'" />';
873: }
1.75 raeburn 874: my $helpitem = &Apache::loncommon::help_open_topic('Modify_Postsubmit_Config');
875: $r->print(<<ENDDOCUMENT);
876: <form action="/adm/modifycourse" method="post" name="setpostsubmit" onsubmit="return verify_postsubmit();">
877: <h3>$lt{'conf'} <span class="LC_nobreak">($cdesc)</span></h3>
878: <p>
879: $helpitem $lt{'disa'}:
1.88 raeburn 880: <label><input type="radio" name="postsubmit" $checkedon onclick="togglePostsubmit('studentsubmission');" value="1" $disabled />
1.75 raeburn 881: $lt{'yes'}</label>
1.89 raeburn 882: <label><input type="radio" name="postsubmit" $checkedoff onclick="togglePostsubmit('studentsubmission');" value="0" $disabled />
1.75 raeburn 883: $lt{'no'}</label>
884: <div id="studentsubmission" style="display: $display">
1.88 raeburn 885: $lt{'nums'} <input type="text" name="postsubtimeout" value="$postsubtimeout" $disabled /><br />
1.75 raeburn 886: $zero</div>
887: <br />
1.88 raeburn 888: $submit
1.75 raeburn 889: </p>
890: $hidden_elements
891: <a href="javascript:changePage(document.setpostsubmit,'menu')">$lt{'back'}</a>
892: </form>
893: ENDDOCUMENT
894: return;
895: }
896:
897: sub domain_postsubtimeout {
898: my ($cdom,$type,$settings) = @_;
899: return unless (ref($settings) eq 'HASH');
900: my $lctype = lc($type);
1.80 raeburn 901: unless (($type eq 'Community') || ($type eq 'Placement')) {
1.75 raeburn 902: $lctype = 'unofficial';
903: if ($settings->{'internal.coursecode'}) {
904: $lctype = 'official';
905: } elsif ($settings->{'internal.textbook'}) {
906: $lctype = 'textbook';
907: }
908: }
909: my %domconfig =
910: &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
911: my $postsubtimeout = 60;
912: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
913: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
914: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
915: if ($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$lctype} ne '') {
916: $postsubtimeout = $domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$lctype};
917: }
918: }
919: }
920: }
921: return $postsubtimeout;
922: }
923:
1.38 raeburn 924: sub print_catsettings {
1.88 raeburn 925: my ($r,$cdom,$cnum,$cdesc,$type,$readonly) = @_;
1.48 raeburn 926: &print_header($r,$type);
1.38 raeburn 927: my %lt = &Apache::lonlocal::texthash(
1.48 raeburn 928: 'back' => 'Pick another action',
929: 'catset' => 'Catalog Settings for Course',
930: 'visi' => 'Visibility in Course/Community Catalog',
931: 'exclude' => 'Exclude from course catalog:',
932: 'categ' => 'Categorize Course',
933: 'assi' => 'Assign one or more categories and/or subcategories to this course.'
1.38 raeburn 934: );
1.48 raeburn 935: if ($type eq 'Community') {
936: $lt{'catset'} = &mt('Catalog Settings for Community');
937: $lt{'exclude'} = &mt('Exclude from course catalog');
938: $lt{'categ'} = &mt('Categorize Community');
1.49 raeburn 939: $lt{'assi'} = &mt('Assign one or more subcategories to this community.');
1.48 raeburn 940: }
1.38 raeburn 941: $r->print('<form action="/adm/modifycourse" method="post" name="catsettings">'.
1.48 raeburn 942: '<h3>'.$lt{'catset'}.' <span class="LC_nobreak">'.$cdesc.'</span></h3>');
1.38 raeburn 943: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49 raeburn 944: my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38 raeburn 945: if (@cat_params > 0) {
1.88 raeburn 946: my $disabled;
947: if ($readonly) {
948: $disabled = ' disabled="disabled"';
949: }
1.38 raeburn 950: my %currsettings =
951: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
952: if (grep(/^togglecats$/,@cat_params)) {
953: my $excludeon = '';
954: my $excludeoff = ' checked="checked" ';
955: if ($currsettings{'hidefromcat'} eq 'yes') {
956: $excludeon = $excludeoff;
957: $excludeoff = '';
958: }
1.48 raeburn 959: $r->print('<br /><h4>'.$lt{'visi'}.'</h4>'.
960: $lt{'exclude'}.
1.88 raeburn 961: ' <label><input name="hidefromcat" type="radio" value="yes" '.$excludeon.$disabled.' />'.&mt('Yes').'</label> <label><input name="hidefromcat" type="radio" value="" '.$excludeoff.$disabled.' />'.&mt('No').'</label><br /><p>');
1.48 raeburn 962: if ($type eq 'Community') {
963: $r->print(&mt("If a community has been categorized using at least one of the categories defined for communities in the domain, it will be listed in the domain's publicly accessible Course/Community Catalog, unless excluded."));
1.81 raeburn 964: } elsif ($type eq 'Placement') {
965: $r->print(&mt("If a placement test has been categorized using at least one of the categories defined for placement tests in the domain, it will be listed in the domain's publicly accessible Course/Community Catalog, unless excluded."));
1.48 raeburn 966: } else {
967: $r->print(&mt("Unless excluded, a course will be listed in the domain's publicly accessible Course/Community Catalog, if at least one of the following applies").':<ul>'.
968: '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code.').'</li>'.
969: '<li>'.&mt('The course has been categorized using at least one of the course categories defined for the domain.').'</li></ul>');
970: }
971: $r->print('</ul></p>');
1.38 raeburn 972: }
973: if (grep(/^categorize$/,@cat_params)) {
1.48 raeburn 974: $r->print('<br /><h4>'.$lt{'categ'}.'</h4>');
1.38 raeburn 975: if (ref($domconf{'coursecategories'}) eq 'HASH') {
976: my $cathash = $domconf{'coursecategories'}{'cats'};
977: if (ref($cathash) eq 'HASH') {
1.48 raeburn 978: $r->print($lt{'assi'}.'<br /><br />'.
1.38 raeburn 979: &Apache::loncommon::assign_categories_table($cathash,
1.88 raeburn 980: $currsettings{'categories'},$type,$disabled));
1.38 raeburn 981: } else {
982: $r->print(&mt('No categories defined for this domain'));
983: }
984: } else {
985: $r->print(&mt('No categories defined for this domain'));
986: }
1.81 raeburn 987: unless (($type eq 'Community') || ($type eq 'Placement')) {
1.48 raeburn 988: $r->print('<p>'.&mt('If auto-cataloging based on institutional code is enabled in the domain, a course will continue to be listed in the catalog of official courses, in addition to receiving a listing under any manually assigned categor(ies).').'</p>');
989: }
1.38 raeburn 990: }
1.88 raeburn 991: unless ($readonly) {
992: $r->print('<p><input type="button" name="chgcatsettings" value="'.
993: &mt('Save').'" onclick="javascript:changePage(document.catsettings,'."'processcat'".');" /></p>');
994: }
1.38 raeburn 995: } else {
1.48 raeburn 996: $r->print('<span class="LC_warning">');
997: if ($type eq 'Community') {
998: $r->print(&mt('Catalog settings in this domain are set in community context via "Community Configuration".'));
999: } else {
1000: $r->print(&mt('Catalog settings in this domain are set in course context via "Course Configuration".'));
1001: }
1002: $r->print('</span><br /><br />'."\n".
1.38 raeburn 1003: '<a href="javascript:changePage(document.catsettings,'."'menu'".');">'.
1004: $lt{'back'}.'</a>');
1005: }
1006: $r->print(&hidden_form_elements().'</form>'."\n");
1007: return;
1008: }
1009:
1.28 raeburn 1010: sub print_course_modification_page {
1.88 raeburn 1011: my ($r,$cdom,$cnum,$cdesc,$crstype,$readonly) = @_;
1.2 raeburn 1012: my %lt=&Apache::lonlocal::texthash(
1013: 'actv' => "Active",
1014: 'inac' => "Inactive",
1015: 'ownr' => "Owner",
1016: 'name' => "Name",
1.26 raeburn 1017: 'unme' => "Username:Domain",
1.2 raeburn 1018: 'stus' => "Status",
1.48 raeburn 1019: 'nocc' => 'There is currently no owner set for this course.',
1.32 raeburn 1020: 'gobt' => "Save",
1.72 raeburn 1021: 'sett' => 'Setting',
1022: 'domd' => 'Domain default',
1023: 'whom' => 'Who configures',
1.2 raeburn 1024: );
1.88 raeburn 1025: my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname,$disabled);
1.48 raeburn 1026: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.72 raeburn 1027: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.textbook',
1.85 raeburn 1028: 'internal.selfenrollmgrdc','internal.selfenrollmgrcc',
1.89 raeburn 1029: 'internal.mysqltables'],$cdom,$cnum);
1.72 raeburn 1030: my $type = &Apache::lonuserutils::get_extended_type($cdom,$cnum,$crstype,\%settings);
1031: my @specific_managebydc = split(/,/,$settings{'internal.selfenrollmgrdc'});
1032: my @specific_managebycc = split(/,/,$settings{'internal.selfenrollmgrcc'});
1033: my %domdefaults = &Apache::lonnet::get_domain_defaults($cdom);
1034: my @default_managebydc = split(/,/,$domdefaults{$type.'selfenrolladmdc'});
1035: if ($crstype eq 'Community') {
1.48 raeburn 1036: $ccrole = 'co';
1037: $lt{'nocc'} = &mt('There is currently no owner set for this community.');
1038: } else {
1039: $ccrole ='cc';
1.88 raeburn 1040: ($javascript_validations,$authenitems) = &gather_authenitems($cdom,\%enrollvar,$readonly);
1.48 raeburn 1041: }
1.72 raeburn 1042: $ccname = &Apache::lonnet::plaintext($ccrole,$crstype);
1.88 raeburn 1043: if ($readonly) {
1044: $disabled = ' disabled="disabled"';
1045: }
1.48 raeburn 1046: my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,'','',[$ccrole]);
1047: my (@local_ccs,%cc_status,%pname);
1048: foreach my $item (keys(%roleshash)) {
1049: my ($uname,$udom) = split(/:/,$item);
1050: if (!grep(/^\Q$uname\E:\Q$udom\E$/,@local_ccs)) {
1051: push(@local_ccs,$uname.':'.$udom);
1052: $pname{$uname.':'.$udom} = &Apache::loncommon::plainname($uname,$udom);
1053: $cc_status{$uname.':'.$udom} = $lt{'actv'};
1.1 raeburn 1054: }
1055: }
1.48 raeburn 1056: if (($enrollvar{'courseowner'} ne '') &&
1057: (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs))) {
1058: push(@local_ccs,$enrollvar{'courseowner'});
1.26 raeburn 1059: my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
1060: $pname{$enrollvar{'courseowner'}} =
1061: &Apache::loncommon::plainname($owneruname,$ownerdom);
1.48 raeburn 1062: my $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
1063: $cdom,$cnum,$ccrole);
1.19 raeburn 1064: if ($active_cc eq 'active') {
1.2 raeburn 1065: $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1 raeburn 1066: } else {
1.2 raeburn 1067: $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1 raeburn 1068: }
1069: }
1.48 raeburn 1070: @local_ccs = sort(@local_ccs);
1071: if (@local_ccs == 0) {
1072: $ownertable = $lt{'nocc'};
1073: } else {
1074: my $numlocalcc = scalar(@local_ccs);
1075: $ownertable = '<input type="hidden" name="numlocalcc" value="'.$numlocalcc.'" />'.
1076: &Apache::loncommon::start_data_table()."\n".
1077: &Apache::loncommon::start_data_table_header_row()."\n".
1078: '<th>'.$lt{'ownr'}.'</th>'.
1079: '<th>'.$lt{'name'}.'</th>'.
1080: '<th>'.$lt{'unme'}.'</th>'.
1081: '<th>'.$lt{'stus'}.'</th>'.
1082: &Apache::loncommon::end_data_table_header_row()."\n";
1083: foreach my $cc (@local_ccs) {
1084: $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
1085: if ($cc eq $enrollvar{'courseowner'}) {
1.88 raeburn 1086: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked"'.$disabled.' /></td>'."\n";
1.48 raeburn 1087: } else {
1.88 raeburn 1088: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'"'.$disabled.' /></td>'."\n";
1.48 raeburn 1089: }
1090: $ownertable .=
1091: '<td>'.$pname{$cc}.'</td>'."\n".
1092: '<td>'.$cc.'</td>'."\n".
1093: '<td>'.$cc_status{$cc}.' '.$ccname.'</td>'."\n".
1094: &Apache::loncommon::end_data_table_row()."\n";
1095: }
1096: $ownertable .= &Apache::loncommon::end_data_table();
1097: }
1.72 raeburn 1098: &print_header($r,$crstype,$javascript_validations);
1.48 raeburn 1099: my $dctitle = &Apache::lonnet::plaintext('dc');
1.72 raeburn 1100: my $mainheader = &modifiable_only_title($crstype);
1.48 raeburn 1101: my $hidden_elements = &hidden_form_elements();
1102: $r->print('<form action="/adm/modifycourse" method="post" name="'.$env{'form.phase'}.'">'."\n".
1103: '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3><p>'.
1104: &Apache::lonhtmlcommon::start_pick_box());
1.72 raeburn 1105: if ($crstype eq 'Community') {
1.48 raeburn 1106: $r->print(&Apache::lonhtmlcommon::row_title(
1107: &Apache::loncommon::help_open_topic('Modify_Community_Owner').
1108: ' '.&mt('Community Owner'))."\n");
1109: } else {
1110: $r->print(&Apache::lonhtmlcommon::row_title(
1111: &Apache::loncommon::help_open_topic('Modify_Course_Instcode').
1112: ' '.&mt('Course Code'))."\n".
1.91 ! raeburn 1113: '<input type="text" size="15" name="coursecode" value="'.$enrollvar{'coursecode'}.'"'.$disabled.' />'.
1.60 raeburn 1114: &Apache::lonhtmlcommon::row_closure());
1.83 raeburn 1115: if (($crstype eq 'Course') && (&showcredits($cdom))) {
1.60 raeburn 1116: $r->print(&Apache::lonhtmlcommon::row_title(
1117: &Apache::loncommon::help_open_topic('Modify_Course_Credithours').
1118: ' '.&mt('Credits (students)'))."\n".
1.88 raeburn 1119: '<input type="text" size="3" name="defaultcredits" value="'.$enrollvar{'defaultcredits'}.'"'.$disabled.' />'.
1.60 raeburn 1120: &Apache::lonhtmlcommon::row_closure());
1.83 raeburn 1121: }
1122: $r->print(&Apache::lonhtmlcommon::row_title(
1123: &Apache::loncommon::help_open_topic('Modify_Course_Defaultauth').
1124: ' '.&mt('Default Authentication method'))."\n".
1125: $authenitems."\n".
1126: &Apache::lonhtmlcommon::row_closure().
1127: &Apache::lonhtmlcommon::row_title(
1128: &Apache::loncommon::help_open_topic('Modify_Course_Owner').
1129: ' '.&mt('Course Owner'))."\n");
1.48 raeburn 1130: }
1.72 raeburn 1131: my ($cctitle,$rolename,$currmanages,$ccchecked,$dcchecked,$defaultchecked);
1132: my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
1133: if ($type eq 'Community') {
1134: $cctitle = &mt('Community personnel');
1135: } else {
1136: $cctitle = &mt('Course personnel');
1137: }
1138:
1139: $r->print($ownertable."\n".&Apache::lonhtmlcommon::row_closure().
1140: &Apache::lonhtmlcommon::row_title(
1141: &Apache::loncommon::help_open_topic('Modify_Course_Selfenrolladmin').
1142: ' '.&mt('Self-enrollment configuration')).
1143: &Apache::loncommon::start_data_table()."\n".
1144: &Apache::loncommon::start_data_table_header_row()."\n".
1145: '<th>'.$lt{'sett'}.'</th>'.
1146: '<th>'.$lt{'domd'}.'</th>'.
1147: '<th>'.$lt{'whom'}.'</th>'.
1148: &Apache::loncommon::end_data_table_header_row()."\n");
1149: my %optionname;
1150: $optionname{''} = &mt('Use domain default');
1151: $optionname{'0'} = $dctitle;
1152: $optionname{'1'} = $cctitle;
1153: foreach my $item (@{$selfenrollrows}) {
1154: my %checked;
1155: my $default = $cctitle;
1156: if (grep(/^\Q$item\E$/,@default_managebydc)) {
1157: $default = $dctitle;
1158: }
1159: if (grep(/^\Q$item\E$/,@specific_managebydc)) {
1160: $checked{'0'} = ' checked="checked"';
1161: } elsif (grep(/^\Q$item\E$/,@specific_managebycc)) {
1162: $checked{'1'} = ' checked="checked"';
1163: } else {
1164: $checked{''} = ' checked="checked"';
1165: }
1166: $r->print(&Apache::loncommon::start_data_table_row()."\n".
1167: '<td>'.$selfenrolltitles->{$item}.'</td>'."\n".
1168: '<td>'.&mt('[_1] configures',$default).'</td>'."\n".
1169: '<td>');
1170: foreach my $option ('','0','1') {
1171: $r->print('<span class="LC_nobreak"><label>'.
1172: '<input type="radio" name="selfenrollmgr_'.$item.'" '.
1.88 raeburn 1173: 'value="'.$option.'"'.$checked{$option}.$disabled.' />'.
1.72 raeburn 1174: $optionname{$option}.'</label></span><br />');
1175: }
1176: $r->print('</td>'."\n".
1177: &Apache::loncommon::end_data_table_row()."\n");
1178: }
1179: $r->print(&Apache::loncommon::end_data_table()."\n".
1.85 raeburn 1180: '<br />'.&Apache::lonhtmlcommon::row_closure().
1181: &Apache::lonhtmlcommon::row_title(
1182: &Apache::loncommon::help_open_topic('Modify_Course_Table_Lifetime').
1183: ' '.&mt('"Temporary" Tables Lifetime (s)'))."\n".
1.88 raeburn 1184: '<input type="text" size="10" name="mysqltables" value="'.$settings{'internal.mysqltables'}.'"'.$disabled.' />'.
1.85 raeburn 1185: &Apache::lonhtmlcommon::row_closure(1).
1.88 raeburn 1186: &Apache::lonhtmlcommon::end_pick_box().'</p><p>'.$hidden_elements);
1187: unless ($readonly) {
1188: $r->print('<input type="button" onclick="javascript:changePage(this.form,'."'processparms'".');');
1189: if ($crstype eq 'Community') {
1190: $r->print('this.form.submit();"');
1191: } else {
1192: $r->print('javascript:verify_message(this.form);"');
1193: }
1194: $r->print(' value="'.$lt{'gobt'}.'" />');
1.48 raeburn 1195: }
1.88 raeburn 1196: $r->print('</p></form>');
1.48 raeburn 1197: return;
1198: }
1199:
1.72 raeburn 1200: sub print_selfenrollconfig {
1.88 raeburn 1201: my ($r,$type,$cdesc,$coursehash,$readonly) = @_;
1.72 raeburn 1202: return unless(ref($coursehash) eq 'HASH');
1203: my $cnum = $coursehash->{'num'};
1204: my $cdom = $coursehash->{'domain'};
1205: my %currsettings = &get_selfenroll_settings($coursehash);
1206: &print_header($r,$type);
1207: $r->print('<h3>'.&mt('Self-enrollment with a student role in: [_1]',
1208: '<span class="LC_nobreak">'.$cdesc.'</span>').'</h3>'."\n");
1209: &Apache::loncreateuser::print_selfenroll_menu($r,'domain',$env{'form.pickedcourse'},
1210: $cdom,$cnum,\%currsettings,
1.88 raeburn 1211: &hidden_form_elements(),$readonly);
1.72 raeburn 1212: return;
1213: }
1214:
1215: sub modify_selfenrollconfig {
1216: my ($r,$type,$cdesc,$coursehash) = @_;
1217: return unless(ref($coursehash) eq 'HASH');
1218: my $cnum = $coursehash->{'num'};
1219: my $cdom = $coursehash->{'domain'};
1220: my %currsettings = &get_selfenroll_settings($coursehash);
1221: &print_header($r,$type);
1222: $r->print('<h3>'.&mt('Self-enrollment with a student role in: [_1]',
1223: '<span class="LC_nobreak">'.$cdesc.'</span>').'</h3>'."\n");
1224: $r->print('<form action="/adm/modifycourse" method="post" name="selfenroll">'."\n".
1225: &hidden_form_elements().'<br />');
1226: &Apache::loncreateuser::update_selfenroll_config($r,$env{'form.pickedcourse'},
1.73 raeburn 1227: $cdom,$cnum,'domain',$type,\%currsettings);
1.72 raeburn 1228: $r->print('</form>');
1229: return;
1230: }
1231:
1232: sub get_selfenroll_settings {
1233: my ($coursehash) = @_;
1234: my %currsettings;
1235: if (ref($coursehash) eq 'HASH') {
1236: %currsettings = (
1237: selfenroll_types => $coursehash->{'internal.selfenroll_types'},
1238: selfenroll_registered => $coursehash->{'internal.selfenroll_registered'},
1239: selfenroll_section => $coursehash->{'internal.selfenroll_section'},
1240: selfenroll_notifylist => $coursehash->{'internal.selfenroll_notifylist'},
1241: selfenroll_approval => $coursehash->{'internal.selfenroll_approval'},
1242: selfenroll_limit => $coursehash->{'internal.selfenroll_limit'},
1243: selfenroll_cap => $coursehash->{'internal.selfenroll_cap'},
1244: selfenroll_start_date => $coursehash->{'internal.selfenroll_start_date'},
1245: selfenroll_end_date => $coursehash->{'internal.selfenroll_end_date'},
1246: selfenroll_start_access => $coursehash->{'internal.selfenroll_start_access'},
1247: selfenroll_end_access => $coursehash->{'internal.selfenroll_end_access'},
1248: default_enrollment_start_date => $coursehash->{'default_enrollment_start_date'},
1249: default_enrollment_end_date => $coursehash->{'default_enrollment_end_date'},
1.73 raeburn 1250: uniquecode => $coursehash->{'internal.uniquecode'},
1.72 raeburn 1251: );
1252: }
1253: return %currsettings;
1254: }
1255:
1.48 raeburn 1256: sub modifiable_only_title {
1257: my ($type) = @_;
1258: my $dctitle = &Apache::lonnet::plaintext('dc');
1259: if ($type eq 'Community') {
1260: return &mt('Community settings modifiable only by [_1] for:',$dctitle);
1261: } else {
1262: return &mt('Course settings modifiable only by [_1] for:',$dctitle);
1263: }
1264: }
1.24 albertel 1265:
1.48 raeburn 1266: sub gather_authenitems {
1.88 raeburn 1267: my ($cdom,$enrollvar,$readonly) = @_;
1.28 raeburn 1268: my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
1.2 raeburn 1269: my $curr_authtype = '';
1270: my $curr_authfield = '';
1.48 raeburn 1271: if (ref($enrollvar) eq 'HASH') {
1272: if ($enrollvar->{'authtype'} =~ /^krb/) {
1273: $curr_authtype = 'krb';
1274: } elsif ($enrollvar->{'authtype'} eq 'internal' ) {
1275: $curr_authtype = 'int';
1276: } elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
1277: $curr_authtype = 'loc';
1278: }
1.2 raeburn 1279: }
1280: unless ($curr_authtype eq '') {
1281: $curr_authfield = $curr_authtype.'arg';
1.33 raeburn 1282: }
1.48 raeburn 1283: my $javascript_validations =
1284: &Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,
1285: $curr_authtype,$curr_authfield);
1.35 raeburn 1286: my %param = ( formname => 'document.'.$env{'form.phase'},
1.48 raeburn 1287: kerb_def_dom => $krbdefdom,
1288: kerb_def_auth => $krbdef,
1.2 raeburn 1289: mode => 'modifycourse',
1290: curr_authtype => $curr_authtype,
1.88 raeburn 1291: curr_autharg => $enrollvar->{'autharg'},
1292: readonly => $readonly,
1.48 raeburn 1293: );
1.32 raeburn 1294: my (%authform,$authenitems);
1295: $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
1296: $authform{'int'} = &Apache::loncommon::authform_internal(%param);
1297: $authform{'loc'} = &Apache::loncommon::authform_local(%param);
1298: foreach my $item ('krb','int','loc') {
1299: if ($authform{$item} ne '') {
1300: $authenitems .= $authform{$item}.'<br />';
1301: }
1.1 raeburn 1302: }
1.48 raeburn 1303: return($javascript_validations,$authenitems);
1.1 raeburn 1304: }
1305:
1306: sub modify_course {
1.30 raeburn 1307: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1.48 raeburn 1308: my %longtype = &course_settings_descrip($type);
1.50 raeburn 1309: my @items = ('internal.courseowner','description','internal.co-owners',
1.72 raeburn 1310: 'internal.pendingco-owners','internal.selfenrollmgrdc',
1.85 raeburn 1311: 'internal.selfenrollmgrcc','internal.mysqltables');
1.72 raeburn 1312: my ($selfenrollrows,$selfenrolltitles) = &Apache::lonuserutils::get_selfenroll_titles();
1.81 raeburn 1313: unless (($type eq 'Community') || ($type eq 'Placement')) {
1.48 raeburn 1314: push(@items,('internal.coursecode','internal.authtype','internal.autharg',
1315: 'internal.sectionnums','internal.crosslistings'));
1.60 raeburn 1316: if (&showcredits($cdom)) {
1317: push(@items,'internal.defaultcredits');
1318: }
1.1 raeburn 1319: }
1.48 raeburn 1320: my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
1321: my $description = $settings{'description'};
1.60 raeburn 1322: my ($ccrole,$response,$chgresponse,$nochgresponse,$reply,%currattr,%newattr,
1323: %cenv,%changed,@changes,@nochanges,@sections,@xlists,@warnings);
1324: my @modifiable_params = &get_dc_settable($type,$cdom);
1.28 raeburn 1325: foreach my $param (@modifiable_params) {
1.48 raeburn 1326: $currattr{$param} = $settings{'internal.'.$param};
1.1 raeburn 1327: }
1.48 raeburn 1328: if ($type eq 'Community') {
1329: %changed = ( owner => 0 );
1330: $ccrole = 'co';
1331: } else {
1332: %changed = ( code => 0,
1333: owner => 0,
1334: );
1335: $ccrole = 'cc';
1336: unless ($settings{'internal.sectionnums'} eq '') {
1337: if ($settings{'internal.sectionnums'} =~ m/,/) {
1338: @sections = split/,/,$settings{'internal.sectionnums'};
1339: } else {
1340: $sections[0] = $settings{'internal.sectionnums'};
1341: }
1342: }
1.60 raeburn 1343: unless ($settings{'internal.crosslistings'} eq '') {
1.48 raeburn 1344: if ($settings{'internal.crosslistings'} =~ m/,/) {
1345: @xlists = split/,/,$settings{'internal.crosslistings'};
1346: } else {
1347: $xlists[0] = $settings{'internal.crosslistings'};
1348: }
1349: }
1350: if ($env{'form.login'} eq 'krb') {
1351: $newattr{'authtype'} = $env{'form.login'};
1352: $newattr{'authtype'} .= $env{'form.krbver'};
1353: $newattr{'autharg'} = $env{'form.krbarg'};
1354: } elsif ($env{'form.login'} eq 'int') {
1355: $newattr{'authtype'} ='internal';
1356: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
1357: $newattr{'autharg'} = $env{'form.intarg'};
1358: }
1359: } elsif ($env{'form.login'} eq 'loc') {
1360: $newattr{'authtype'} = 'localauth';
1361: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
1362: $newattr{'autharg'} = $env{'form.locarg'};
1363: }
1364: }
1365: if ( $newattr{'authtype'}=~ /^krb/) {
1366: if ($newattr{'autharg'} eq '') {
1367: push(@warnings,
1368: &mt('As you did not include the default Kerberos domain'
1.45 bisitz 1369: .' to be used for authentication in this class, the'
1370: .' institutional data used by the automated'
1371: .' enrollment process must include the Kerberos'
1.48 raeburn 1372: .' domain for each new student.'));
1373: }
1374: }
1375:
1376: if ( exists($env{'form.coursecode'}) ) {
1377: $newattr{'coursecode'}=$env{'form.coursecode'};
1378: unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
1379: $changed{'code'} = 1;
1380: }
1.1 raeburn 1381: }
1.85 raeburn 1382: if ( exists($env{'form.mysqltables'}) ) {
1383: $newattr{'mysqltables'} = $env{'form.mysqltables'};
1384: $newattr{'mysqltables'} =~ s/\D+//g;
1385: }
1.83 raeburn 1386: if (($type ne 'Placement') && (&showcredits($cdom) && exists($env{'form.defaultcredits'}))) {
1.85 raeburn 1387: $newattr{'defaultcredits'}=$env{'form.defaultcredits'};
1.60 raeburn 1388: $newattr{'defaultcredits'} =~ s/[^\d\.]//g;
1389: }
1.72 raeburn 1390: }
1391:
1392: my @newmgrdc = ();
1393: my @newmgrcc = ();
1394: my @currmgrdc = split(/,/,$currattr{'selfenrollmgrdc'});
1395: my @currmgrcc = split(/,/,$currattr{'selfenrollmgrcc'});
1.60 raeburn 1396:
1.72 raeburn 1397: foreach my $item (@{$selfenrollrows}) {
1398: if ($env{'form.selfenrollmgr_'.$item} eq '0') {
1399: push(@newmgrdc,$item);
1400: } elsif ($env{'form.selfenrollmgr_'.$item} eq '1') {
1401: push(@newmgrcc,$item);
1402: }
1403: }
1404:
1405: $newattr{'selfenrollmgrdc'}=join(',',@newmgrdc);
1406: $newattr{'selfenrollmgrcc'}=join(',',@newmgrcc);
1407:
1408: my $cctitle;
1409: if ($type eq 'Community') {
1410: $cctitle = &mt('Community personnel');
1411: } else {
1412: $cctitle = &mt('Course personnel');
1.1 raeburn 1413: }
1.72 raeburn 1414: my $dctitle = &Apache::lonnet::plaintext('dc');
1.1 raeburn 1415:
1.16 albertel 1416: if ( exists($env{'form.courseowner'}) ) {
1417: $newattr{'courseowner'}=$env{'form.courseowner'};
1.14 raeburn 1418: unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
1.38 raeburn 1419: $changed{'owner'} = 1;
1.1 raeburn 1420: }
1421: }
1.48 raeburn 1422:
1.50 raeburn 1423: if ($changed{'owner'} || $changed{'code'}) {
1.38 raeburn 1424: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
1425: undef,undef,'.');
1426: if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
1.48 raeburn 1427: if ($changed{'code'}) {
1428: $crsinfo{$env{'form.pickedcourse'}}{'inst_code'} = $env{'form.coursecode'};
1429: }
1430: if ($changed{'owner'}) {
1431: $crsinfo{$env{'form.pickedcourse'}}{'owner'} = $env{'form.courseowner'};
1432: }
1.38 raeburn 1433: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1434: my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
1.50 raeburn 1435: if ($putres eq 'ok') {
1436: &update_coowners($cdom,$cnum,$chome,\%settings,\%newattr);
1437: }
1.38 raeburn 1438: }
1.14 raeburn 1439: }
1.28 raeburn 1440: foreach my $param (@modifiable_params) {
1441: if ($currattr{$param} eq $newattr{$param}) {
1442: push(@nochanges,$param);
1.1 raeburn 1443: } else {
1.48 raeburn 1444: $cenv{'internal.'.$param} = $newattr{$param};
1.28 raeburn 1445: push(@changes,$param);
1.1 raeburn 1446: }
1447: }
1448: if (@changes > 0) {
1.62 bisitz 1449: $chgresponse = &mt('The following settings have been changed:').'<br/><ul>';
1.1 raeburn 1450: }
1.48 raeburn 1451: if (@nochanges > 0) {
1.62 bisitz 1452: $nochgresponse = &mt('The following settings remain unchanged:').'<br/><ul>';
1.1 raeburn 1453: }
1.33 raeburn 1454: if (@changes > 0) {
1.28 raeburn 1455: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1.1 raeburn 1456: if ($putreply !~ /^ok$/) {
1.48 raeburn 1457: $response = '<p class="LC_error">'.
1458: &mt('There was a problem processing your requested changes.').'<br />';
1459: if ($type eq 'Community') {
1460: $response .= &mt('Settings for this community have been left unchanged.');
1461: } else {
1462: $response .= &mt('Settings for this course have been left unchanged.');
1463: }
1464: $response .= '<br/>'.&mt('Error: ').$putreply.'</p>';
1.1 raeburn 1465: } else {
1.72 raeburn 1466: if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
1467: my %newenv;
1468: map { $newenv{'course.'.$cdom.'_'.$cnum.'.internal.'.$_} = $newattr{$_}; } @changes;
1469: &Apache::lonnet::appenv(\%newenv);
1470: }
1.28 raeburn 1471: foreach my $attr (@modifiable_params) {
1.48 raeburn 1472: if (grep/^\Q$attr\E$/,@changes) {
1.72 raeburn 1473: my $shown = $newattr{$attr};
1474: if ($attr eq 'selfenrollmgrdc') {
1475: $shown = &selfenroll_config_status(\@newmgrdc,$selfenrolltitles);
1476: } elsif ($attr eq 'selfenrollmgrcc') {
1477: $shown = &selfenroll_config_status(\@newmgrcc,$selfenrolltitles);
1478: } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
1479: $shown = &mt('None');
1.85 raeburn 1480: } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
1481: $shown = &mt('domain default');
1.72 raeburn 1482: }
1483: $chgresponse .= '<li>'.&mt('[_1] now set to: [_2]',$longtype{$attr},$shown).'</li>';
1.1 raeburn 1484: } else {
1.72 raeburn 1485: my $shown = $currattr{$attr};
1486: if ($attr eq 'selfenrollmgrdc') {
1487: $shown = &selfenroll_config_status(\@currmgrdc,$selfenrolltitles);
1488: } elsif ($attr eq 'selfenrollmgrcc') {
1489: $shown = &selfenroll_config_status(\@currmgrcc,$selfenrolltitles);
1490: } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
1491: $shown = &mt('None');
1.85 raeburn 1492: } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
1493: $shown = &mt('domain default');
1.72 raeburn 1494: }
1495: $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
1.1 raeburn 1496: }
1497: }
1.81 raeburn 1498: if (($type ne 'Community') && ($type ne 'Placement') && ($changed{'code'} || $changed{'owner'})) {
1.1 raeburn 1499: if ( $newattr{'courseowner'} eq '') {
1.48 raeburn 1500: push(@warnings,&mt('There is no owner associated with this LON-CAPA course.').
1501: '<br />'.&mt('If automated enrollment at your institution requires validation of course owners, automated enrollment will fail.'));
1.1 raeburn 1502: } else {
1.59 raeburn 1503: my %crsenv = &Apache::lonnet::get('environment',['internal.co-owners'],$cdom,$cnum);
1504: my $coowners = $crsenv{'internal.co-owners'};
1.1 raeburn 1505: if (@sections > 0) {
1.38 raeburn 1506: if ($changed{'code'}) {
1.2 raeburn 1507: foreach my $sec (@sections) {
1508: if ($sec =~ m/^(.+):/) {
1.48 raeburn 1509: my $instsec = $1;
1.8 raeburn 1510: my $inst_course_id = $newattr{'coursecode'}.$1;
1.28 raeburn 1511: my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
1.7 raeburn 1512: if ($course_check eq 'ok') {
1.58 raeburn 1513: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners);
1.48 raeburn 1514: unless ($outcome eq 'ok') {
1515:
1.53 raeburn 1516: push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3] for the following reason: "[_4]".',$description,$newattr{'coursecode'},$instsec,$outcome).'<br/>');
1.1 raeburn 1517: }
1518: } else {
1.53 raeburn 1519: push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3] for the following reason: "[_4]".',$description,$newattr{'coursecode'},$instsec,$course_check));
1.1 raeburn 1520: }
1521: } else {
1.48 raeburn 1522: push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3], because this is not a valid section entry.',$description,$newattr{'coursecode'},$sec));
1.1 raeburn 1523: }
1524: }
1.38 raeburn 1525: } elsif ($changed{'owner'}) {
1.4 raeburn 1526: foreach my $sec (@sections) {
1527: if ($sec =~ m/^(.+):/) {
1.48 raeburn 1528: my $instsec = $1;
1529: my $inst_course_id = $newattr{'coursecode'}.$instsec;
1.58 raeburn 1530: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners);
1.4 raeburn 1531: unless ($outcome eq 'ok') {
1.53 raeburn 1532: push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3] for the following reason: "[_4]".',$description,$newattr{'coursecode'},$instsec,$outcome));
1.4 raeburn 1533: }
1534: } else {
1.53 raeburn 1535: push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for "[_2]" - section: [_3], because this is not a valid section entry.',$description,$newattr{'coursecode'},$sec));
1.4 raeburn 1536: }
1537: }
1538: }
1.1 raeburn 1539: } else {
1.53 raeburn 1540: push(@warnings,&mt('As no section numbers are currently listed for "[_1]", automated enrollment will not occur for any sections of institutional course code: "[_2]".',$description,$newattr{'coursecode'}));
1.1 raeburn 1541: }
1.38 raeburn 1542: if ( (@xlists > 0) && ($changed{'owner'}) ) {
1.1 raeburn 1543: foreach my $xlist (@xlists) {
1544: if ($xlist =~ m/^(.+):/) {
1.48 raeburn 1545: my $instxlist = $1;
1.58 raeburn 1546: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$instxlist,$newattr{'courseowner'},$coowners);
1.1 raeburn 1547: unless ($outcome eq 'ok') {
1.48 raeburn 1548: push(@warnings,&mt('If automatic enrollment is enabled for "[_1]", automated enrollment may fail for crosslisted class "[_2]" for the following reason: "[_3]".',$description,$instxlist,$outcome));
1.1 raeburn 1549: }
1.28 raeburn 1550: }
1.1 raeburn 1551: }
1552: }
1553: }
1554: }
1555: }
1.2 raeburn 1556: } else {
1.28 raeburn 1557: foreach my $attr (@modifiable_params) {
1.72 raeburn 1558: my $shown = $currattr{$attr};
1559: if ($attr eq 'selfenrollmgrdc') {
1560: $shown = &selfenroll_config_status(\@currmgrdc,$selfenrolltitles);
1561: } elsif ($attr eq 'selfenrollmgrcc') {
1562: $shown = &selfenroll_config_status(\@currmgrcc,$selfenrolltitles);
1563: } elsif (($attr eq 'defaultcredits') && ($shown eq '')) {
1564: $shown = &mt('None');
1.85 raeburn 1565: } elsif (($attr eq 'mysqltables') && ($shown eq '')) {
1566: $shown = &mt('domain default');
1.72 raeburn 1567: }
1568: $nochgresponse .= '<li>'.&mt('[_1] still set to: [_2]',$longtype{$attr},$shown).'</li>';
1.2 raeburn 1569: }
1.1 raeburn 1570: }
1571:
1572: if (@changes > 0) {
1573: $chgresponse .= "</ul><br/><br/>";
1574: }
1575: if (@nochanges > 0) {
1576: $nochgresponse .= "</ul><br/><br/>";
1577: }
1.48 raeburn 1578: my ($warning,$numwarnings);
1579: my $numwarnings = scalar(@warnings);
1580: if ($numwarnings) {
1581: $warning = &mt('The following [quant,_1,warning was,warnings were] generated when applying your changes to automated enrollment:',$numwarnings).'<p><ul>';
1582: foreach my $warn (@warnings) {
1583: $warning .= '<li><span class="LC_warning">'.$warn.'</span></li>';
1584: }
1585: $warning .= '</ul></p>';
1.1 raeburn 1586: }
1.48 raeburn 1587: if ($response) {
1588: $reply = $response;
1589: } else {
1.1 raeburn 1590: $reply = $chgresponse.$nochgresponse.$warning;
1591: }
1.48 raeburn 1592: &print_header($r,$type);
1593: my $mainheader = &modifiable_only_title($type);
1594: $reply = '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n".
1595: '<p>'.$reply.'</p>'."\n".
1.28 raeburn 1596: '<form action="/adm/modifycourse" method="post" name="processparms">'.
1.66 bisitz 1597: &hidden_form_elements();
1598: my @actions =
1599: ('<a href="javascript:changePage(document.processparms,'."'menu'".')">'.
1600: &mt('Pick another action').'</a>');
1.48 raeburn 1601: if ($numwarnings) {
1602: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
1603: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
1604: '=1&destinationurl=/adm/populate','&<>"');
1605:
1.66 bisitz 1606: push(@actions, '<a href="'.$escuri.'">'.
1607: &mt('Go to Automated Enrollment Manager for course').'</a>');
1.48 raeburn 1608: }
1.66 bisitz 1609: $reply .= &Apache::lonhtmlcommon::actionbox(\@actions).'</form>';
1.3 raeburn 1610: $r->print($reply);
1.28 raeburn 1611: return;
1612: }
1613:
1.72 raeburn 1614: sub selfenroll_config_status {
1615: my ($items,$selfenrolltitles) = @_;
1616: my $shown;
1617: if ((ref($items) eq 'ARRAY') && (ref($selfenrolltitles) eq 'HASH')) {
1618: if (@{$items} > 0) {
1619: $shown = '<ul>';
1620: foreach my $item (@{$items}) {
1621: $shown .= '<li>'.$selfenrolltitles->{$item}.'</li>';
1622: }
1623: $shown .= '</ul>';
1624: } else {
1625: $shown = &mt('None');
1626: }
1627: }
1628: return $shown;
1629: }
1630:
1.50 raeburn 1631: sub update_coowners {
1632: my ($cdom,$cnum,$chome,$settings,$newattr) = @_;
1633: return unless ((ref($settings) eq 'HASH') && (ref($newattr) eq 'HASH'));
1634: my %designhash = &Apache::loncommon::get_domainconf($cdom);
1635: my (%cchash,$autocoowners);
1636: if ($designhash{$cdom.'.autoassign.co-owners'}) {
1637: $autocoowners = 1;
1638: %cchash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc']);
1639: }
1640: if ($settings->{'internal.courseowner'} ne $newattr->{'courseowner'}) {
1641: my $oldowner_to_coowner;
1.51 raeburn 1642: my @types = ('co-owners');
1.50 raeburn 1643: if (($newattr->{'coursecode'}) && ($autocoowners)) {
1644: my $oldowner = $settings->{'internal.courseowner'};
1645: if ($cchash{$oldowner.':cc'}) {
1.51 raeburn 1646: my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$oldowner);
1647: if ($result eq 'valid') {
1648: if ($settings->{'internal.co-owner'}) {
1649: my @current = split(',',$settings->{'internal.co-owners'});
1650: unless (grep(/^\Q$oldowner\E$/,@current)) {
1651: $oldowner_to_coowner = 1;
1652: }
1653: } else {
1.50 raeburn 1654: $oldowner_to_coowner = 1;
1655: }
1656: }
1657: }
1.51 raeburn 1658: } else {
1659: push(@types,'pendingco-owners');
1.50 raeburn 1660: }
1.51 raeburn 1661: foreach my $type (@types) {
1.50 raeburn 1662: if ($settings->{'internal.'.$type}) {
1663: my @current = split(',',$settings->{'internal.'.$type});
1664: my $newowner = $newattr->{'courseowner'};
1665: my @newvalues = ();
1666: if (($newowner ne '') && (grep(/^\Q$newowner\E$/,@current))) {
1667: foreach my $person (@current) {
1668: unless ($person eq $newowner) {
1669: push(@newvalues,$person);
1670: }
1671: }
1672: } else {
1673: @newvalues = @current;
1674: }
1675: if ($oldowner_to_coowner) {
1676: push(@newvalues,$settings->{'internal.courseowner'});
1677: @newvalues = sort(@newvalues);
1678: }
1679: my $newownstr = join(',',@newvalues);
1680: if ($newownstr ne $settings->{'internal.'.$type}) {
1681: if ($type eq 'co-owners') {
1682: my $deleted = '';
1683: unless (@newvalues) {
1684: $deleted = 1;
1685: }
1686: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
1687: $deleted,@newvalues);
1688: } else {
1689: my $pendingcoowners;
1690: my $cid = $cdom.'_'.$cnum;
1691: if (@newvalues) {
1692: $pendingcoowners = join(',',@newvalues);
1693: my %pendinghash = (
1694: 'internal.pendingco-owners' => $pendingcoowners,
1695: );
1.52 raeburn 1696: my $putresult = &Apache::lonnet::put('environment',\%pendinghash,$cdom,$cnum);
1.50 raeburn 1697: if ($putresult eq 'ok') {
1698: if ($env{'course.'.$cid.'.num'} eq $cnum) {
1.52 raeburn 1699: &Apache::lonnet::appenv({'course.'.$cid.'.internal.pendingco-owners' => $pendingcoowners});
1.50 raeburn 1700: }
1701: }
1702: } else {
1703: my $delresult = &Apache::lonnet::del('environment',['internal.pendingco-owners'],$cdom,$cnum);
1704: if ($delresult eq 'ok') {
1705: if ($env{'course.'.$cid.'.internal.pendingco-owners'}) {
1706: &Apache::lonnet::delenv('course.'.$cid.'.internal.pendingco-owners');
1707: }
1708: }
1709: }
1710: }
1711: } elsif ($oldowner_to_coowner) {
1712: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
1713: $settings->{'internal.courseowner'});
1714:
1715: }
1716: } elsif ($oldowner_to_coowner) {
1717: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
1718: $settings->{'internal.courseowner'});
1719: }
1720: }
1721: }
1722: if ($settings->{'internal.coursecode'} ne $newattr->{'coursecode'}) {
1723: if ($newattr->{'coursecode'} ne '') {
1724: my %designhash = &Apache::loncommon::get_domainconf($cdom);
1725: if ($designhash{$cdom.'.autoassign.co-owners'}) {
1726: my @newcoowners = ();
1727: if ($settings->{'internal.co-owners'}) {
1.58 raeburn 1728: my @currcoown = split(',',$settings->{'internal.co-owners'});
1.50 raeburn 1729: my ($updatecoowners,$delcoowners);
1730: foreach my $person (@currcoown) {
1.51 raeburn 1731: my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$person);
1.50 raeburn 1732: if ($result eq 'valid') {
1733: push(@newcoowners,$person);
1734: }
1735: }
1736: foreach my $item (sort(keys(%cchash))) {
1737: my ($uname,$udom,$urole) = split(':',$item);
1.51 raeburn 1738: next if ($uname.':'.$udom eq $newattr->{'courseowner'});
1.50 raeburn 1739: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@newcoowners)) {
1.51 raeburn 1740: my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$uname.':'.$udom);
1741: if ($result eq 'valid') {
1742: push(@newcoowners,$uname.':'.$udom);
1743: }
1.50 raeburn 1744: }
1745: }
1746: if (@newcoowners) {
1747: my $coowners = join(',',sort(@newcoowners));
1748: unless ($coowners eq $settings->{'internal.co-owners'}) {
1749: $updatecoowners = 1;
1750: }
1751: } else {
1752: $delcoowners = 1;
1753: }
1754: if ($updatecoowners || $delcoowners) {
1755: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
1756: $delcoowners,@newcoowners);
1757: }
1758: } else {
1759: foreach my $item (sort(keys(%cchash))) {
1760: my ($uname,$udom,$urole) = split(':',$item);
1761: push(@newcoowners,$uname.':'.$udom);
1762: }
1763: if (@newcoowners) {
1764: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
1765: @newcoowners);
1766: }
1767: }
1768: }
1769: }
1770: }
1771: return;
1772: }
1773:
1.28 raeburn 1774: sub modify_quota {
1.48 raeburn 1775: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1776: &print_header($r,$type);
1.61 raeburn 1777: my $lctype = lc($type);
1778: my $headline = &mt("Disk space quotas for $lctype: [_1]",
1779: '<span class="LC_nobreak">'.$cdesc.'</span>');
1.48 raeburn 1780: $r->print('<form action="/adm/modifycourse" method="post" name="processquota">'."\n".
1.61 raeburn 1781: '<h3>'.$headline.'</h3>');
1782: my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
1783: my %staticdefaults = (
1784: coursequota => 20,
1785: uploadquota => 500,
1786: );
1787: my %default;
1788: $default{'coursequota'} = $staticdefaults{'coursequota'};
1789: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1790: $default{'uploadquota'} = $domdefs{'uploadquota'};
1791: if ($default{'uploadquota'} eq '') {
1792: $default{'uploadquota'} = $staticdefaults{'uploadquota'};
1793: }
1794: my (%cenv,%showresult);
1795: foreach my $item ('coursequota','uploadquota') {
1796: if ($env{'form.'.$item} ne '') {
1797: my $newquota = $env{'form.'.$item};
1798: if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
1799: $newquota = $1;
1800: if ($oldsettings{'internal.'.$item} == $newquota) {
1801: if ($item eq 'coursequota') {
1802: $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] MB.',$newquota).'<br />');
1803: } else {
1804: $r->print(&mt('The disk space allocated for files uploaded via the Content Editor remains unchanged as [_1] MB.',$newquota).'<br />');
1805: }
1806: } else {
1807: $cenv{'internal.'.$item} = $newquota;
1808: $showresult{$item} = 1;
1809: }
1.28 raeburn 1810: } else {
1.61 raeburn 1811: if ($item eq 'coursequota') {
1812: $r->print(&mt('The proposed group portfolio quota contained invalid characters, so the quota is unchanged.').'<br />');
1813: } else {
1814: $r->print(&mt('The proposed quota for content uploaded via the Content Editor contained invalid characters, so the quota is unchanged.').'<br />');
1815:
1816: }
1817: }
1818: }
1819: }
1820: if (keys(%cenv)) {
1821: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
1822: $cnum);
1823: foreach my $key (sort(keys(%showresult))) {
1824: if (($oldsettings{'internal.'.$key} eq '') &&
1825: ($env{'form.'.$key} == $default{$key})) {
1826: if ($key eq 'uploadquota') {
1827: if ($type eq 'Community') {
1828: $r->print(&mt('The disk space allocated for files uploaded to this community via the Content Editor is the default quota for this domain: [_1] MB.',
1829: $default{$key}).'<br />');
1830: } else {
1831: $r->print(&mt('The disk space allocated for files uploaded to this course via the Content Editor is the default quota for this domain: [_1] MB.',
1832: $default{$key}).'<br />');
1833: }
1834: } else {
1.48 raeburn 1835: if ($type eq 'Community') {
1.61 raeburn 1836: $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] MB.',
1837: $default{$key}).'<br />');
1.48 raeburn 1838: } else {
1.61 raeburn 1839: $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] MB.',
1840: $default{$key}).'<br />');
1.48 raeburn 1841: }
1.61 raeburn 1842: }
1843: delete($showresult{$key});
1844: }
1845: }
1846: if ($putreply eq 'ok') {
1847: my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
1848: if ($showresult{'coursequota'}) {
1849: $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] MB.',
1850: '<b>'.$updatedsettings{'internal.coursequota'}.'</b>').'<br />');
1851: my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
1852: if ($usage >= $updatedsettings{'internal.coursequota'}) {
1853: my $newoverquota;
1854: if ($usage < $oldsettings{'internal.coursequota'}) {
1855: $newoverquota = 'now';
1856: }
1857: $r->print('<p>');
1858: if ($type eq 'Community') {
1.67 bisitz 1859: $r->print(&mt("Disk usage $newoverquota exceeds the quota for this community.").' '.
1.61 raeburn 1860: &mt('Upload of new portfolio files and assignment of a non-zero MB quota to new groups in the community will not be possible until some files have been deleted, and total usage is below community quota.'));
1.28 raeburn 1861: } else {
1.67 bisitz 1862: $r->print(&mt("Disk usage $newoverquota exceeds the quota for this course.").' '.
1.61 raeburn 1863: &mt('Upload of new portfolio files and assignment of a non-zero MB quota to new groups in the course will not be possible until some files have been deleted, and total usage is below course quota.'));
1.28 raeburn 1864: }
1.61 raeburn 1865: $r->print('</p>');
1.28 raeburn 1866: }
1867: }
1.61 raeburn 1868: if ($showresult{'uploadquota'}) {
1869: $r->print(&mt('The disk space allocated for content uploaded directly via the Content Editor is now: [_1] MB.',
1870: '<b>'.$updatedsettings{'internal.uploadquota'}.'</b>').'<br />');
1871: }
1.28 raeburn 1872: } else {
1.63 raeburn 1873: $r->print(&mt('An error occurred storing the quota(s) for group portfolio files and/or uploaded content: ').
1.61 raeburn 1874: $putreply);
1.28 raeburn 1875: }
1876: }
1.48 raeburn 1877: $r->print('<p>'.
1878: '<a href="javascript:changePage(document.processquota,'."'menu'".')">'.
1879: &mt('Pick another action').'</a>');
1.28 raeburn 1880: $r->print(&hidden_form_elements().'</form>');
1881: return;
1.1 raeburn 1882: }
1883:
1.57 raeburn 1884: sub modify_anonsurvey_threshold {
1885: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1886: &print_header($r,$type);
1887: $r->print('<form action="/adm/modifycourse" method="post" name="processthreshold">'."\n".
1888: '<h3>'.&mt('Responder threshold required for display of anonymous survey submissions:').
1889: ' <span class="LC_nobreak">'.$cdesc.'</span></h3><br />');
1890: my %oldsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
1891: my %domconfig =
1892: &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
1893: my $defaultthreshold;
1894: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
1895: $defaultthreshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
1896: if ($defaultthreshold eq '') {
1897: $defaultthreshold = 10;
1898: }
1899: } else {
1900: $defaultthreshold = 10;
1901: }
1902: if ($env{'form.threshold'} eq '') {
1903: $r->print(&mt('The proposed responder threshold for display of anonymous survey submissions was blank, so the threshold is unchanged.'));
1904: } else {
1905: my $newthreshold = $env{'form.threshold'};
1906: if ($newthreshold =~ /^\s*(\d+)\s*$/) {
1907: $newthreshold = $1;
1908: if ($oldsettings{'internal.anonsurvey_threshold'} eq $env{'form.threshold'}) {
1909: $r->print(&mt('Responder threshold for anonymous survey submissions display remains unchanged: [_1].',$env{'form.threshold'}));
1910: } else {
1911: my %cenv = (
1912: 'internal.anonsurvey_threshold' => $env{'form.threshold'},
1913: );
1914: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
1915: $cnum);
1.72 raeburn 1916: if ($putreply eq 'ok') {
1917: if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
1918: &Apache::lonnet::appenv(
1919: {'course.'.$cdom.'_'.$cnum.'.internal.anonsurvey_threshold' => $env{'form.threshold'}});
1920: }
1921: }
1.57 raeburn 1922: if (($oldsettings{'internal.anonsurvey_threshold'} eq '') &&
1923: ($env{'form.threshold'} == $defaultthreshold)) {
1924: $r->print(&mt('The responder threshold for display of anonymous survey submissions is the default for this domain: [_1].',$defaultthreshold));
1925: } else {
1926: if ($putreply eq 'ok') {
1927: my %updatedsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
1928: $r->print(&mt('The responder threshold for display of anonymous survey submissions is now: [_1].','<b>'.$updatedsettings{'internal.anonsurvey_threshold'}.'</b>'));
1929: } else {
1930: $r->print(&mt('An error occurred storing the responder threshold for anonymous submissions display: ').
1931: $putreply);
1932: }
1933: }
1934: }
1935: } else {
1936: $r->print(&mt('The proposed responder threshold for display of anonymous submissions contained invalid characters, so the threshold is unchanged.'));
1937: }
1938: }
1939: $r->print('<p>'.
1940: '<a href="javascript:changePage(document.processthreshold,'."'menu'".')">'.
1.75 raeburn 1941: &mt('Pick another action').'</a></p>');
1942: $r->print(&hidden_form_elements().'</form>');
1943: return;
1944: }
1945:
1946: sub modify_postsubmit_config {
1947: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1948: &print_header($r,$type);
1949: my %lt = &Apache::lonlocal::texthash(
1950: subb => 'Submit button behavior after student makes a submission:',
1951: unch => 'Post submission behavior of the Submit button is unchanged.',
1952: erro => 'An error occurred when saving your proposed changes.',
1953: inva => 'An invalid response was recorded.',
1954: pick => 'Pick another action',
1955: );
1956: $r->print('<form action="/adm/modifycourse" method="post" name="processpostsubmit">'."\n".
1957: '<h3>'.$lt{'subb'}.' <span class="LC_nobreak">('.$cdesc.')</span></h3><br />');
1958: my %oldsettings =
1959: &Apache::lonnet::get('environment',['internal.postsubmit','internal.postsubtimeout','internal.coursecode','internal.textbook'],$cdom,$cnum);
1960: my $postsubmit = $env{'form.postsubmit'};
1961: if ($postsubmit eq '1') {
1962: my $postsubtimeout = $env{'form.postsubtimeout'};
1963: $postsubtimeout =~ s/[^\d\.]+//g;
1964: if (($oldsettings{'internal.postsubmit'} eq $postsubmit) && ($oldsettings{'internal.postsubtimeout'} eq $postsubtimeout)) {
1965: $r->print($lt{'unch'});
1966: } else {
1967: my %cenv = (
1968: 'internal.postsubmit' => $postsubmit,
1969: );
1970: if ($postsubtimeout eq '') {
1971: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1972: if ($putreply eq 'ok') {
1973: my $defaulttimeout = &domain_postsubtimeout($cdom,$type,\%oldsettings);
1974: $r->print(&mt('The proposed duration for disabling the Submit button post-submission was blank, so the domain default of [quant,_1,second] will be used.',$defaulttimeout));
1975: if (exists($oldsettings{'internal.postsubtimeout'})) {
1976: &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum);
1977: }
1978: } else {
1979: $r->print($lt{'erro'});
1980: }
1981: } else {
1982: $cenv{'internal.postsubtimeout'} = $postsubtimeout;
1983: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1984: if ($putreply eq 'ok') {
1985: if ($postsubtimeout eq '0') {
1986: $r->print(&mt('Submit button will be disabled after student submission until page is reloaded.'));
1987: } else {
1988: $r->print(&mt('Submit button will be disabled after student submission for [quant,_1,second].',$postsubtimeout));
1989: }
1990: } else {
1991: $r->print($lt{'erro'});
1992: }
1993: }
1994: }
1995: } elsif ($postsubmit eq '0') {
1996: if ($oldsettings{'internal.postsubmit'} eq $postsubmit) {
1997: $r->print($lt{'unch'});
1998: } else {
1999: if (exists($oldsettings{'internal.postsubtimeout'})) {
2000: &Apache::lonnet::del('environment',['internal.postsubtimeout'],$cdom,$cnum);
2001: }
2002: my %cenv = (
2003: 'internal.postsubmit' => $postsubmit,
2004: );
2005: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
2006: if ($putreply eq 'ok') {
1.76 droeschl 2007: $r->print(&mt('Submit button will not be disabled after student submission'));
1.75 raeburn 2008: } else {
2009: $r->print($lt{'erro'});
2010: }
2011: }
2012: } else {
2013: $r->print($lt{'inva'}.' '.$lt{'unch'});
2014: }
2015: $r->print('<p>'.
2016: '<a href="javascript:changePage(document.processpostsubmit,'."'menu'".')">'.
2017: &mt('Pick another action').'</a></p>');
1.57 raeburn 2018: $r->print(&hidden_form_elements().'</form>');
2019: return;
2020: }
2021:
1.38 raeburn 2022: sub modify_catsettings {
1.48 raeburn 2023: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
2024: &print_header($r,$type);
2025: my ($ccrole,%desc);
2026: if ($type eq 'Community') {
2027: $desc{'hidefromcat'} = &mt('Excluded from community catalog');
2028: $desc{'categories'} = &mt('Assigned categories for this community');
2029: $ccrole = 'co';
2030: } else {
2031: $desc{'hidefromcat'} = &mt('Excluded from course catalog');
2032: $desc{'categories'} = &mt('Assigned categories for this course');
2033: $ccrole = 'cc';
2034: }
1.38 raeburn 2035: $r->print('
2036: <form action="/adm/modifycourse" method="post" name="processcat">
2037: <h3>'.&mt('Category settings').'</h3>');
2038: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49 raeburn 2039: my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38 raeburn 2040: if (@cat_params > 0) {
2041: my (%cenv,@changes,@nochanges);
2042: my %currsettings =
2043: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
2044: my (@newcategories,%showitem);
2045: if (grep(/^togglecats$/,@cat_params)) {
2046: if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) {
2047: push(@changes,'hidefromcat');
2048: $cenv{'hidefromcat'} = $env{'form.hidefromcat'};
2049: } else {
2050: push(@nochanges,'hidefromcat');
2051: }
2052: if ($env{'form.hidefromcat'} eq 'yes') {
2053: $showitem{'hidefromcat'} = '"'.&mt('Yes')."'";
2054: } else {
2055: $showitem{'hidefromcat'} = '"'.&mt('No').'"';
2056: }
2057: }
2058: if (grep(/^categorize$/,@cat_params)) {
2059: my (@cats,@trails,%allitems,%idx,@jsarray);
2060: if (ref($domconf{'coursecategories'}) eq 'HASH') {
2061: my $cathash = $domconf{'coursecategories'}{'cats'};
2062: if (ref($cathash) eq 'HASH') {
2063: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
2064: \%allitems,\%idx,\@jsarray);
2065: }
2066: }
2067: @newcategories = &Apache::loncommon::get_env_multiple('form.usecategory');
2068: if (@newcategories == 0) {
2069: $showitem{'categories'} = '"'.&mt('None').'"';
2070: } else {
2071: $showitem{'categories'} = '<ul>';
2072: foreach my $item (@newcategories) {
2073: $showitem{'categories'} .= '<li>'.$trails[$allitems{$item}].'</li>';
2074: }
2075: $showitem{'categories'} .= '</ul>';
2076: }
2077: my $catchg = 0;
2078: if ($currsettings{'categories'} ne '') {
2079: my @currcategories = split('&',$currsettings{'categories'});
2080: foreach my $cat (@currcategories) {
2081: if (!grep(/^\Q$cat\E$/,@newcategories)) {
2082: $catchg = 1;
2083: last;
2084: }
2085: }
2086: if (!$catchg) {
2087: foreach my $cat (@newcategories) {
2088: if (!grep(/^\Q$cat\E$/,@currcategories)) {
2089: $catchg = 1;
2090: last;
2091: }
2092: }
2093: }
2094: } else {
2095: if (@newcategories > 0) {
2096: $catchg = 1;
2097: }
2098: }
2099: if ($catchg) {
2100: $cenv{'categories'} = join('&',@newcategories);
2101: push(@changes,'categories');
2102: } else {
2103: push(@nochanges,'categories');
2104: }
2105: if (@changes > 0) {
2106: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
2107: if ($putreply eq 'ok') {
1.72 raeburn 2108: if ($env{'course.'.$cdom.'_'.$cnum.'.description'} ne '') {
2109: my %newenvhash;
2110: foreach my $item (@changes) {
2111: $newenvhash{'course.'.$cdom.'_'.$cnum.'.'.$item} = $cenv{$item};
2112: }
2113: &Apache::lonnet::appenv(\%newenvhash);
2114: }
1.38 raeburn 2115: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
2116: $cnum,undef,undef,'.');
2117: if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
2118: if (grep(/^hidefromcat$/,@changes)) {
2119: $crsinfo{$env{'form.pickedcourse'}}{'hidefromcat'} = $env{'form.hidefromcat'};
2120: }
2121: if (grep(/^categories$/,@changes)) {
2122: $crsinfo{$env{'form.pickedcourse'}}{'categories'} = $cenv{'categories'};
2123: }
2124: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
2125: my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
2126: }
1.48 raeburn 2127: $r->print(&mt('The following changes occurred:').'<ul>');
1.38 raeburn 2128: foreach my $item (@changes) {
1.48 raeburn 2129: $r->print('<li>'.&mt('[_1] now set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38 raeburn 2130: }
2131: $r->print('</ul><br />');
2132: }
2133: }
2134: if (@nochanges > 0) {
1.48 raeburn 2135: $r->print(&mt('The following were unchanged:').'<ul>');
1.38 raeburn 2136: foreach my $item (@nochanges) {
1.48 raeburn 2137: $r->print('<li>'.&mt('[_1] still set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38 raeburn 2138: }
2139: $r->print('</ul>');
2140: }
2141: }
2142: } else {
1.48 raeburn 2143: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
2144: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
2145: '=1&destinationurl=/adm/courseprefs','&<>"');
2146: if ($type eq 'Community') {
2147: $r->print(&mt('Category settings for communities in this domain should be modified in community context (via "[_1]Community Configuration[_2]").','<a href="$escuri">','</a>').'<br />');
2148: } else {
2149: $r->print(&mt('Category settings for courses in this domain should be modified in course context (via "[_1]Course Configuration[_2]").','<a href="$escuri">','</a>').'<br />');
2150: }
1.38 raeburn 2151: }
2152: $r->print('<br />'."\n".
2153: '<a href="javascript:changePage(document.processcat,'."'menu'".')">'.
1.48 raeburn 2154: &mt('Pick another action').'</a>');
1.38 raeburn 2155: $r->print(&hidden_form_elements().'</form>');
2156: return;
2157: }
2158:
1.1 raeburn 2159: sub print_header {
1.48 raeburn 2160: my ($r,$type,$javascript_validations) = @_;
1.28 raeburn 2161: my $phase = "start";
2162: if ( exists($env{'form.phase'}) ) {
2163: $phase = $env{'form.phase'};
2164: }
2165: my $js = qq|
1.60 raeburn 2166:
1.28 raeburn 2167: function changePage(formname,newphase) {
2168: formname.phase.value = newphase;
2169: if (newphase == 'processparms') {
2170: return;
1.1 raeburn 2171: }
1.28 raeburn 2172: formname.submit();
2173: }
1.60 raeburn 2174:
1.28 raeburn 2175: |;
2176: if ($phase eq 'setparms') {
1.60 raeburn 2177: $js .= $javascript_validations;
1.28 raeburn 2178: } elsif ($phase eq 'courselist') {
1.90 raeburn 2179: $js .= <<"ENDJS";
1.60 raeburn 2180: function hide_searching() {
2181: if (document.getElementById('searching')) {
2182: document.getElementById('searching').style.display = 'none';
2183: }
2184: return;
2185: }
2186:
1.90 raeburn 2187: ENDJS
1.28 raeburn 2188: } elsif ($phase eq 'setquota') {
1.57 raeburn 2189: my $invalid = &mt('The quota you entered contained invalid characters.');
2190: my $alert = &mt('You must enter a number');
1.78 damieng 2191: &js_escape(\$invalid);
2192: &js_escape(\$alert);
1.57 raeburn 2193: my $regexp = '/^\s*(\d+\.?\d*|\.\d+)\s*$/';
2194: $js .= <<"ENDSCRIPT";
1.60 raeburn 2195:
1.57 raeburn 2196: function verify_quota() {
2197: var newquota = document.setquota.coursequota.value;
2198: var num_reg = $regexp;
1.28 raeburn 2199: if (num_reg.test(newquota)) {
1.57 raeburn 2200: changePage(document.setquota,'processquota');
1.1 raeburn 2201: } else {
1.57 raeburn 2202: alert("$invalid\\n$alert");
2203: return false;
1.1 raeburn 2204: }
1.57 raeburn 2205: return true;
2206: }
1.60 raeburn 2207:
1.57 raeburn 2208: ENDSCRIPT
2209: } elsif ($phase eq 'setanon') {
2210: my $invalid = &mt('The responder threshold you entered is invalid.');
2211: my $alert = &mt('You must enter a positive integer.');
1.78 damieng 2212: &js_escape(\$invalid);
2213: &js_escape(\$alert);
1.57 raeburn 2214: my $regexp = ' /^\s*\d+\s*$/';
2215: $js .= <<"ENDSCRIPT";
1.60 raeburn 2216:
1.57 raeburn 2217: function verify_anon_threshold() {
2218: var newthreshold = document.setanon.threshold.value;
2219: var num_reg = $regexp;
2220: if (num_reg.test(newthreshold)) {
2221: if (newthreshold > 0) {
2222: changePage(document.setanon,'processthreshold');
2223: } else {
2224: alert("$invalid\\n$alert");
2225: return false;
2226: }
2227: } else {
2228: alert("$invalid\\n$alert");
2229: return false;
2230: }
2231: return true;
1.28 raeburn 2232: }
1.60 raeburn 2233:
1.28 raeburn 2234: ENDSCRIPT
1.75 raeburn 2235: } elsif ($phase eq 'setpostsubmit') {
2236: my $invalid = &mt('The choice entered for disabling the submit button is invalid.');
2237: my $invalidtimeout = &mt('The timeout you entered for disabling the submit button is invalid.');
2238: my $alert = &mt('Enter one of: a positive integer, 0 (for no timeout), or leave blank to use domain default');
1.78 damieng 2239: &js_escape(\$invalid);
2240: &js_escape(\$invalidtimeout);
2241: &js_escape(\$alert);
1.75 raeburn 2242: my $regexp = ' /^\s*\d+\s*$/';
2243:
2244: $js .= <<"ENDSCRIPT";
2245:
2246: function verify_postsubmit() {
2247: var optionsElement = document.setpostsubmit.postsubmit;
2248: var verified = '';
2249: if (optionsElement.length) {
2250: var currval;
2251: for (var i=0; i<optionsElement.length; i++) {
2252: if (optionsElement[i].checked) {
2253: currval = optionsElement[i].value;
2254: }
2255: }
2256: if (currval == 1) {
2257: var newtimeout = document.setpostsubmit.postsubtimeout.value;
2258: if (newtimeout == '') {
2259: verified = 'ok';
2260: } else {
2261: var num_reg = $regexp;
2262: if (num_reg.test(newtimeout)) {
2263: if (newtimeout>= 0) {
2264: verified = 'ok';
2265: } else {
2266: alert("$invalidtimeout\\n$alert");
2267: return false;
2268: }
2269: } else {
2270: alert("$invalid\\n$alert");
2271: return false;
2272: }
2273: }
2274: } else {
2275: if (currval == 0) {
2276: verified = 'ok';
2277: } else {
2278: alert('$invalid');
2279: return false;
2280: }
2281: }
2282: if (verified == 'ok') {
2283: changePage(document.setpostsubmit,'processpostsubmit');
2284: return true;
2285: }
2286: }
2287: return false;
2288: }
2289:
2290: function togglePostsubmit(caller) {
2291: var optionsElement = document.setpostsubmit.postsubmit;
2292: if (document.getElementById(caller)) {
2293: var divitem = document.getElementById(caller);
2294: var optionsElement = document.setpostsubmit.postsubmit;
2295: if (optionsElement.length) {
2296: var currval;
2297: for (var i=0; i<optionsElement.length; i++) {
2298: if (optionsElement[i].checked) {
2299: currval = optionsElement[i].value;
2300: }
2301: }
2302: if (currval == 1) {
2303: divitem.style.display = 'block';
2304: } else {
2305: divitem.style.display = 'none';
2306: }
2307: }
1.1 raeburn 2308: }
1.75 raeburn 2309: return;
2310: }
1.60 raeburn 2311:
1.75 raeburn 2312: ENDSCRIPT
2313:
2314: }
1.37 raeburn 2315: my $starthash;
1.86 raeburn 2316: if ($env{'form.phase'} eq 'adhocrole') {
1.37 raeburn 2317: $starthash = {
1.86 raeburn 2318: add_entries => {'onload' => "javascript:document.adhocrole.submit();"},
1.37 raeburn 2319: };
1.60 raeburn 2320: } elsif ($phase eq 'courselist') {
2321: $starthash = {
1.74 musolffc 2322: add_entries => {'onload' => "hide_searching(); courseSet(document.filterpicker.official, 'load');"},
1.60 raeburn 2323: };
1.37 raeburn 2324: }
1.48 raeburn 2325: $r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
1.60 raeburn 2326: &Apache::lonhtmlcommon::scripttag($js),
2327: $starthash));
1.48 raeburn 2328: my $bread_text = "View/Modify Courses/Communities";
2329: if ($type eq 'Community') {
2330: $bread_text = 'Community Settings';
1.81 raeburn 2331: } elsif ($type eq 'Placement') {
2332: $bread_text = 'Placement Test Settings';
1.41 raeburn 2333: } else {
1.48 raeburn 2334: $bread_text = 'Course Settings';
1.41 raeburn 2335: }
1.48 raeburn 2336: $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
1.5 raeburn 2337: return;
1.1 raeburn 2338: }
2339:
2340: sub print_footer {
1.23 albertel 2341: my ($r) = @_;
2342: $r->print('<br />'.&Apache::loncommon::end_page());
1.5 raeburn 2343: return;
1.3 raeburn 2344: }
2345:
2346: sub check_course {
1.71 raeburn 2347: my ($dom,$domdesc) = @_;
2348: my ($ok_course,$description,$instcode);
2349: my %coursehash;
2350: if ($env{'form.pickedcourse'} =~ /^$match_domain\_$match_courseid$/) {
2351: my %args;
2352: unless ($env{'course.'.$env{'form.pickedcourse'}.'.description'}) {
2353: %args = (
2354: 'one_time' => 1,
2355: 'freshen_cache' => 1,
2356: );
2357: }
2358: %coursehash =
2359: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
2360: my $cnum = $coursehash{'num'};
2361: my $cdom = $coursehash{'domain'};
2362: $description = $coursehash{'description'};
2363: $instcode = $coursehash{'internal.coursecode'};
2364: if ($instcode) {
2365: $description .= " ($instcode)";
2366: }
2367: if (($cdom eq $dom) && ($cnum =~ /^$match_courseid$/)) {
2368: my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
2369: $cnum,undef,undef,'.');
2370: if ($courseIDs{$cdom.'_'.$cnum}) {
2371: $ok_course = 'ok';
1.5 raeburn 2372: }
1.3 raeburn 2373: }
2374: }
1.71 raeburn 2375: return ($ok_course,$description,\%coursehash);
1.1 raeburn 2376: }
2377:
1.28 raeburn 2378: sub course_settings_descrip {
1.48 raeburn 2379: my ($type) = @_;
2380: my %longtype;
2381: if ($type eq 'Community') {
2382: %longtype = &Apache::lonlocal::texthash(
1.72 raeburn 2383: 'courseowner' => "Username:domain of community owner",
2384: 'co-owners' => "Username:domain of each co-owner",
2385: 'selfenrollmgrdc' => "Community-specific self-enrollment configuration by Domain Coordinator",
2386: 'selfenrollmgrcc' => "Community-specific self-enrollment configuration by Community personnel",
1.85 raeburn 2387: 'mysqltables' => '"Temporary" student performance tables lifetime (seconds)',
1.48 raeburn 2388: );
2389: } else {
2390: %longtype = &Apache::lonlocal::texthash(
1.28 raeburn 2391: 'authtype' => 'Default authentication method',
2392: 'autharg' => 'Default authentication parameter',
2393: 'autoadds' => 'Automated adds',
2394: 'autodrops' => 'Automated drops',
2395: 'autostart' => 'Date of first automated enrollment',
2396: 'autoend' => 'Date of last automated enrollment',
2397: 'default_enrollment_start_date' => 'Date of first student access',
2398: 'default_enrollment_end_date' => 'Date of last student access',
2399: 'coursecode' => 'Official course code',
2400: 'courseowner' => "Username:domain of course owner",
1.50 raeburn 2401: 'co-owners' => "Username:domain of each co-owner",
1.28 raeburn 2402: 'notifylist' => 'Course Coordinators to be notified of enrollment changes',
1.48 raeburn 2403: 'sectionnums' => 'Course section number:LON-CAPA section',
2404: 'crosslistings' => 'Crosslisted class:LON-CAPA section',
1.72 raeburn 2405: 'defaultcredits' => 'Credits',
1.84 raeburn 2406: 'autodropfailsafe' => "Failsafe section enrollment count",
1.72 raeburn 2407: 'selfenrollmgrdc' => "Course-specific self-enrollment configuration by Domain Coordinator",
2408: 'selfenrollmgrcc' => "Course-specific self-enrollment configuration by Course personnel",
1.85 raeburn 2409: 'mysqltables' => '"Temporary" student performance tables lifetime (seconds)',
1.48 raeburn 2410: );
2411: }
1.28 raeburn 2412: return %longtype;
2413: }
2414:
2415: sub hidden_form_elements {
2416: my $hidden_elements =
1.46 raeburn 2417: &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
1.37 raeburn 2418: 'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
1.57 raeburn 2419: 'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
1.75 raeburn 2420: 'threshold','postsubmit','postsubtimeout','defaultcredits','uploadquota',
2421: 'selfenrollmgrdc','selfenrollmgrcc','action','state','currsec_st',
1.85 raeburn 2422: 'sections','newsec','mysqltables'],['^selfenrollmgr_','^selfenroll_'])."\n".
1.37 raeburn 2423: '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
1.28 raeburn 2424: return $hidden_elements;
2425: }
1.1 raeburn 2426:
1.60 raeburn 2427: sub showcredits {
2428: my ($dom) = @_;
2429: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.79 raeburn 2430: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'} || $domdefaults{'textbookcredits'}) {
1.60 raeburn 2431: return 1;
2432: }
2433: }
2434:
1.86 raeburn 2435: sub get_permission {
2436: my ($dom) = @_;
2437: my ($allowed,%permission);
2438: if (&Apache::lonnet::allowed('ccc',$dom)) {
2439: $allowed = 1;
2440: %permission = (
1.88 raeburn 2441: setquota => 'edit',
2442: processquota => 'edit',
2443: setanon => 'edit',
2444: processthreshold => 'edit',
2445: setpostsubmit => 'edit',
2446: processpostsubmit => 'edit',
2447: viewparms => 'view',
2448: setparms => 'edit',
2449: processparms => 'edit',
2450: catsettings => 'edit',
2451: processcat => 'edit',
2452: selfenroll => 'edit',
1.90 raeburn 2453: adhocrole => 'coord',
1.86 raeburn 2454: );
2455: } elsif (&Apache::lonnet::allowed('rar',$dom)) {
2456: $allowed = 1;
2457: %permission = (
1.88 raeburn 2458: setquota => 'view',
2459: viewparms => 'view',
2460: setanon => 'view',
2461: setpostsubmit => 'view',
2462: setparms => 'view',
2463: catsettings => 'view',
2464: selfenroll => 'view',
1.90 raeburn 2465: adhocrole => 'custom',
1.86 raeburn 2466: );
2467: }
2468: return ($allowed,\%permission);
2469: }
2470:
1.1 raeburn 2471: sub handler {
2472: my $r = shift;
2473: if ($r->header_only) {
2474: &Apache::loncommon::content_type($r,'text/html');
2475: $r->send_http_header;
2476: return OK;
2477: }
1.72 raeburn 2478:
1.28 raeburn 2479: my $dom = $env{'request.role.domain'};
1.31 albertel 2480: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.86 raeburn 2481: my ($allowed,$permission) = &get_permission($dom);
2482: if ($allowed) {
1.1 raeburn 2483: &Apache::loncommon::content_type($r,'text/html');
2484: $r->send_http_header;
2485:
1.28 raeburn 2486: &Apache::lonhtmlcommon::clear_breadcrumbs();
2487:
2488: my $phase = $env{'form.phase'};
1.46 raeburn 2489: if ($env{'form.updater'}) {
2490: $phase = '';
2491: }
1.37 raeburn 2492: if ($phase eq '') {
2493: &Apache::lonhtmlcommon::add_breadcrumb
1.28 raeburn 2494: ({href=>"/adm/modifycourse",
1.48 raeburn 2495: text=>"Course/Community search"});
1.28 raeburn 2496: &print_course_search_page($r,$dom,$domdesc);
1.1 raeburn 2497: } else {
1.37 raeburn 2498: my $firstform = $phase;
2499: if ($phase eq 'courselist') {
2500: $firstform = 'filterpicker';
1.48 raeburn 2501: }
2502: my $choose_text;
2503: my $type = $env{'form.type'};
2504: if ($type eq '') {
2505: $type = 'Course';
2506: }
2507: if ($type eq 'Community') {
2508: $choose_text = "Choose a community";
1.81 raeburn 2509: } elsif ($type eq 'Placement') {
2510: $choose_text = "Choose a placement test";
1.48 raeburn 2511: } else {
2512: $choose_text = "Choose a course";
1.37 raeburn 2513: }
1.28 raeburn 2514: &Apache::lonhtmlcommon::add_breadcrumb
1.37 raeburn 2515: ({href=>"javascript:changePage(document.$firstform,'')",
1.48 raeburn 2516: text=>"Course/Community search"},
1.37 raeburn 2517: {href=>"javascript:changePage(document.$phase,'courselist')",
1.48 raeburn 2518: text=>$choose_text});
1.28 raeburn 2519: if ($phase eq 'courselist') {
1.90 raeburn 2520: &print_course_selection_page($r,$dom,$domdesc,$permission);
1.28 raeburn 2521: } else {
1.71 raeburn 2522: my ($checked,$cdesc,$coursehash) = &check_course($dom,$domdesc);
1.28 raeburn 2523: if ($checked eq 'ok') {
1.48 raeburn 2524: my $enter_text;
2525: if ($type eq 'Community') {
2526: $enter_text = 'Enter community';
1.81 raeburn 2527: } elsif ($type eq 'Placement') {
2528: $enter_text = 'Enter placement test';
1.48 raeburn 2529: } else {
2530: $enter_text = 'Enter course';
2531: }
1.28 raeburn 2532: if ($phase eq 'menu') {
1.37 raeburn 2533: &Apache::lonhtmlcommon::add_breadcrumb
2534: ({href=>"javascript:changePage(document.$phase,'menu')",
2535: text=>"Pick action"});
1.71 raeburn 2536: &print_modification_menu($r,$cdesc,$domdesc,$dom,$type,
1.86 raeburn 2537: $env{'form.pickedcourse'},$coursehash,
2538: $permission);
2539: } elsif ($phase eq 'adhocrole') {
1.37 raeburn 2540: &Apache::lonhtmlcommon::add_breadcrumb
1.86 raeburn 2541: ({href=>"javascript:changePage(document.$phase,'adhocrole')",
1.48 raeburn 2542: text=>$enter_text});
1.90 raeburn 2543: &print_adhocrole_selected($r,$type,$permission);
1.28 raeburn 2544: } else {
1.37 raeburn 2545: &Apache::lonhtmlcommon::add_breadcrumb
2546: ({href=>"javascript:changePage(document.$phase,'menu')",
2547: text=>"Pick action"});
1.28 raeburn 2548: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
1.88 raeburn 2549: my ($readonly,$linktext);
2550: if ($permission->{$phase} eq 'view') {
2551: $readonly = 1;
2552: }
1.86 raeburn 2553: if (($phase eq 'setquota') && ($permission->{'setquota'})) {
1.88 raeburn 2554: if ($permission->{'setquota'} eq 'view') {
2555: $linktext = 'Set quota';
2556: } else {
2557: $linktext = 'Display quota';
2558: }
1.28 raeburn 2559: &Apache::lonhtmlcommon::add_breadcrumb
2560: ({href=>"javascript:changePage(document.$phase,'$phase')",
1.89 raeburn 2561: text=>$linktext});
1.88 raeburn 2562: &print_setquota($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86 raeburn 2563: } elsif (($phase eq 'processquota') && ($permission->{'processquota'})) {
1.28 raeburn 2564: &Apache::lonhtmlcommon::add_breadcrumb
2565: ({href=>"javascript:changePage(document.$phase,'setquota')",
2566: text=>"Set quota"});
2567: &Apache::lonhtmlcommon::add_breadcrumb
2568: ({href=>"javascript:changePage(document.$phase,'$phase')",
2569: text=>"Result"});
1.48 raeburn 2570: &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86 raeburn 2571: } elsif (($phase eq 'setanon') && ($permission->{'setanon'})) {
1.57 raeburn 2572: &Apache::lonhtmlcommon::add_breadcrumb
2573: ({href=>"javascript:changePage(document.$phase,'$phase')",
2574: text=>"Threshold for anonymous submissions display"});
1.88 raeburn 2575: &print_set_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86 raeburn 2576: } elsif (($phase eq 'processthreshold') && ($permission->{'processthreshold'})) {
1.57 raeburn 2577: &Apache::lonhtmlcommon::add_breadcrumb
2578: ({href=>"javascript:changePage(document.$phase,'setanon')",
2579: text=>"Threshold for anonymous submissions display"});
2580: &Apache::lonhtmlcommon::add_breadcrumb
2581: ({href=>"javascript:changePage(document.$phase,'$phase')",
2582: text=>"Result"});
2583: &modify_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86 raeburn 2584: } elsif (($phase eq 'setpostsubmit') && ($permission->{'setpostsubmit'})) {
1.88 raeburn 2585: if ($permission->{'setpostsubmit'} eq 'view') {
2586: $linktext = 'Submit button behavior post-submission';
2587: } else {
2588: $linktext = 'Configure submit button behavior post-submission';
2589: }
1.75 raeburn 2590: &Apache::lonhtmlcommon::add_breadcrumb
2591: ({href=>"javascript:changePage(document.$phase,'$phase')",
1.89 raeburn 2592: text=>$linktext});
1.88 raeburn 2593: &print_postsubmit_config($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86 raeburn 2594: } elsif (($phase eq 'processpostsubmit') && ($permission->{'processpostsubmit'})) {
1.75 raeburn 2595: &Apache::lonhtmlcommon::add_breadcrumb
2596: ({href=>"javascript:changePage(document.$phase,'$phase')",
2597: text=>"Result"});
2598: &modify_postsubmit_config($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86 raeburn 2599: } elsif (($phase eq 'viewparms') && ($permission->{'viewparms'})) {
1.28 raeburn 2600: &Apache::lonhtmlcommon::add_breadcrumb
2601: ({href=>"javascript:changePage(document.$phase,'viewparms')",
2602: text=>"Display settings"});
1.86 raeburn 2603: &print_settings_display($r,$cdom,$cnum,$cdesc,$type,$permission);
2604: } elsif (($phase eq 'setparms') && ($permission->{'setparms'})) {
1.88 raeburn 2605: if ($permission->{'setparms'} eq 'view') {
2606: $linktext = 'Display settings';
2607: } else {
2608: $linktext = 'Change settings';
2609: }
1.28 raeburn 2610: &Apache::lonhtmlcommon::add_breadcrumb
2611: ({href=>"javascript:changePage(document.$phase,'$phase')",
1.89 raeburn 2612: text=>$linktext});
1.88 raeburn 2613: &print_course_modification_page($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86 raeburn 2614: } elsif (($phase eq 'processparms') && ($permission->{'processparms'})) {
1.28 raeburn 2615: &Apache::lonhtmlcommon::add_breadcrumb
2616: ({href=>"javascript:changePage(document.$phase,'setparms')",
2617: text=>"Change settings"});
2618: &Apache::lonhtmlcommon::add_breadcrumb
2619: ({href=>"javascript:changePage(document.$phase,'$phase')",
2620: text=>"Result"});
1.30 raeburn 2621: &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86 raeburn 2622: } elsif (($phase eq 'catsettings') && ($permission->{'catsettings'})) {
1.38 raeburn 2623: &Apache::lonhtmlcommon::add_breadcrumb
2624: ({href=>"javascript:changePage(document.$phase,'$phase')",
2625: text=>"Catalog settings"});
1.88 raeburn 2626: &print_catsettings($r,$cdom,$cnum,$cdesc,$type,$readonly);
1.86 raeburn 2627: } elsif (($phase eq 'processcat') && ($permission->{'processcat'})) {
1.38 raeburn 2628: &Apache::lonhtmlcommon::add_breadcrumb
2629: ({href=>"javascript:changePage(document.$phase,'catsettings')",
2630: text=>"Catalog settings"});
2631: &Apache::lonhtmlcommon::add_breadcrumb
2632: ({href=>"javascript:changePage(document.$phase,'$phase')",
2633: text=>"Result"});
1.48 raeburn 2634: &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.86 raeburn 2635: } elsif (($phase eq 'selfenroll') && ($permission->{'selfenroll'})) {
1.72 raeburn 2636: &Apache::lonhtmlcommon::add_breadcrumb
2637: ({href => "javascript:changePage(document.$phase,'$phase')",
2638: text => "Self-enrollment settings"});
2639: if (!exists($env{'form.state'})) {
1.88 raeburn 2640: &print_selfenrollconfig($r,$type,$cdesc,$coursehash,$readonly);
1.72 raeburn 2641: } elsif ($env{'form.state'} eq 'done') {
2642: &Apache::lonhtmlcommon::add_breadcrumb
2643: ({href=>"javascript:changePage(document.$phase,'$phase')",
2644: text=>"Result"});
2645: &modify_selfenrollconfig($r,$type,$cdesc,$coursehash);
2646: }
1.28 raeburn 2647: }
2648: }
2649: } else {
1.48 raeburn 2650: $r->print('<span class="LC_error">');
2651: if ($type eq 'Community') {
1.72 raeburn 2652: $r->print(&mt('The community you selected is not a valid community in this domain'));
1.81 raeburn 2653: } elsif ($type eq 'Placement') {
2654: $r->print(&mt('The course you selected is not a valid placement test in this domain'));
1.72 raeburn 2655: } else {
1.48 raeburn 2656: $r->print(&mt('The course you selected is not a valid course in this domain'));
2657: }
2658: $r->print(" ($domdesc)</span>");
1.28 raeburn 2659: }
2660: }
1.1 raeburn 2661: }
1.28 raeburn 2662: &print_footer($r);
1.1 raeburn 2663: } else {
1.16 albertel 2664: $env{'user.error.msg'}=
1.48 raeburn 2665: "/adm/modifycourse:ccc:0:0:Cannot modify course/community settings";
1.1 raeburn 2666: return HTTP_NOT_ACCEPTABLE;
2667: }
2668: return OK;
2669: }
2670:
2671: 1;
2672: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>