Annotation of loncom/interface/lonmodifycourse.pm, revision 1.64
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.64 ! raeburn 4: # $Id: lonmodifycourse.pm,v 1.63 2013/08/30 13:22:23 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.28 raeburn 37: use Apache::lonpickcourse;
1.1 raeburn 38: use lib '/home/httpd/lib/perl';
1.25 www 39: use LONCAPA;
1.1 raeburn 40:
1.28 raeburn 41: sub get_dc_settable {
1.60 raeburn 42: my ($type,$cdom) = @_;
1.48 raeburn 43: if ($type eq 'Community') {
44: return ('courseowner');
45: } else {
1.60 raeburn 46: my @items = ('courseowner','coursecode','authtype','autharg');
47: if (&showcredits($cdom)) {
48: push(@items,'defaultcredits');
49: }
50: return @items;
1.48 raeburn 51: }
52: }
53:
54: sub autoenroll_keys {
1.60 raeburn 55: my $internals = ['coursecode','courseowner','authtype','autharg','defaultcredits',
56: 'autoadds','autodrops','autostart','autoend','sectionnums',
57: 'crosslistings','co-owners'];
1.48 raeburn 58: my $accessdates = ['default_enrollment_start_date','default_enrollment_end_date'];
59: return ($internals,$accessdates);
1.28 raeburn 60: }
61:
1.38 raeburn 62: sub catalog_settable {
1.49 raeburn 63: my ($confhash,$type) = @_;
1.38 raeburn 64: my @settable;
65: if (ref($confhash) eq 'HASH') {
1.49 raeburn 66: if ($type eq 'Community') {
67: if ($confhash->{'togglecatscomm'} ne 'comm') {
68: push(@settable,'togglecats');
69: }
70: if ($confhash->{'categorizecomm'} ne 'comm') {
71: push(@settable,'categorize');
72: }
73: } else {
74: if ($confhash->{'togglecats'} ne 'crs') {
75: push(@settable,'togglecats');
76: }
77: if ($confhash->{'categorize'} ne 'crs') {
78: push(@settable,'categorize');
79: }
1.38 raeburn 80: }
81: } else {
82: push(@settable,('togglecats','categorize'));
83: }
84: return @settable;
85: }
86:
1.28 raeburn 87: sub get_enrollment_settings {
88: my ($cdom,$cnum) = @_;
1.48 raeburn 89: my ($internals,$accessdates) = &autoenroll_keys();
90: my @items;
91: if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
92: @items = map { 'internal.'.$_; } (@{$internals});
93: push(@items,@{$accessdates});
94: }
95: my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
1.28 raeburn 96: my %enrollvar;
97: $enrollvar{'autharg'} = '';
98: $enrollvar{'authtype'} = '';
1.48 raeburn 99: foreach my $item (keys(%settings)) {
1.28 raeburn 100: if ($item =~ m/^internal\.(.+)$/) {
101: my $type = $1;
102: if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
103: if ($settings{$item} == 1) {
104: $enrollvar{$type} = "ON";
105: } else {
106: $enrollvar{$type} = "OFF";
1.10 raeburn 107: }
1.28 raeburn 108: } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
109: if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
1.48 raeburn 110: $enrollvar{$type} = &mt('No end date');
1.28 raeburn 111: } else {
1.48 raeburn 112: $enrollvar{$type} = &Apache::lonlocal::locallocaltime($settings{$item});
1.14 raeburn 113: }
1.50 raeburn 114: } elsif (($type eq 'sectionnums') || ($type eq 'co-owners')) {
1.28 raeburn 115: $enrollvar{$type} = $settings{$item};
116: $enrollvar{$type} =~ s/,/, /g;
117: } elsif ($type eq "authtype"
118: || $type eq "autharg" || $type eq "coursecode"
119: || $type eq "crosslistings") {
120: $enrollvar{$type} = $settings{$item};
1.60 raeburn 121: } elsif ($type eq 'defaultcredits') {
122: if (&showcredits($cdom)) {
123: $enrollvar{$type} = $settings{$item};
124: }
1.28 raeburn 125: } elsif ($type eq 'courseowner') {
126: if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
127: $enrollvar{$type} = $settings{$item};
128: } else {
129: if ($settings{$item} ne '') {
130: $enrollvar{$type} = $settings{$item}.':'.$cdom;
1.26 raeburn 131: }
1.1 raeburn 132: }
1.28 raeburn 133: }
134: } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
135: my $type = $1;
136: if ( ($type eq 'end') && ($settings{$item} == 0) ) {
1.48 raeburn 137: $enrollvar{$item} = &mt('No end date');
1.28 raeburn 138: } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
139: $enrollvar{$item} = 'When enrolled';
140: } else {
1.48 raeburn 141: $enrollvar{$item} = &Apache::lonlocal::locallocaltime($settings{$item});
1.1 raeburn 142: }
143: }
144: }
1.28 raeburn 145: return %enrollvar;
146: }
147:
148: sub print_course_search_page {
149: my ($r,$dom,$domdesc) = @_;
1.48 raeburn 150: my $action = '/adm/modifycourse';
151: my $type = $env{'form.type'};
152: if (!defined($env{'form.type'})) {
153: $type = 'Course';
154: }
155: &print_header($r,$type);
1.28 raeburn 156: my $filterlist = ['descriptfilter',
157: 'instcodefilter','ownerfilter',
1.44 raeburn 158: 'coursefilter'];
1.28 raeburn 159: my $filter = {};
1.56 raeburn 160: my ($numtitles,$cctitle,$dctitle,@codetitles);
1.48 raeburn 161: my $ccrole = 'cc';
162: if ($type eq 'Community') {
163: $ccrole = 'co';
1.46 raeburn 164: }
1.48 raeburn 165: $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.46 raeburn 166: $dctitle = &Apache::lonnet::plaintext('dc');
167: $r->print(&Apache::lonpickcourse::js_changer());
1.48 raeburn 168: if ($type eq 'Community') {
169: $r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
170: } else {
171: $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
1.46 raeburn 172: }
1.28 raeburn 173: $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
1.56 raeburn 174: undef,undef,$filter,$action,\$numtitles,'modifycourse',
175: undef,undef,undef,\@codetitles));
1.48 raeburn 176: if ($type eq 'Community') {
177: $r->print(&mt('Actions available after searching for a community:').'<ul>'.
178: '<li>'.&mt('Enter the community with the role of [_1]',$cctitle).'</li>'."\n".
179: '<li>'.&mt('View or modify community settings which only a [_1] may modify.',$dctitle).
180: '</li>'."\n".'</ul>');
181: } else {
182: $r->print(&mt('Actions available after searching for a course:').'<ul>'.
183: '<li>'.&mt('Enter the course with the role of [_1]',$cctitle).'</li>'."\n".
184: '<li>'.&mt('View or modify course settings which only a [_1] may modify.',$dctitle).
185: '</li>'."\n".'</ul>');
186: }
1.28 raeburn 187: }
188:
189: sub print_course_selection_page {
190: my ($r,$dom,$domdesc) = @_;
1.48 raeburn 191: my $type = $env{'form.type'};
192: if (!defined($type)) {
193: $type = 'Course';
194: }
195: &print_header($r,$type);
1.28 raeburn 196:
197: # Criteria for course search
198: my $filterlist = ['descriptfilter',
199: 'instcodefilter','ownerfilter',
200: 'ownerdomfilter','coursefilter'];
201: my %filter;
202: my $action = '/adm/modifycourse';
203: my $dctitle = &Apache::lonnet::plaintext('dc');
1.56 raeburn 204: my ($numtitles,@codetitles);
1.46 raeburn 205: $r->print(&Apache::lonpickcourse::js_changer());
1.48 raeburn 206: $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
1.28 raeburn 207: $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
1.56 raeburn 208: undef,undef,\%filter,$action,\$numtitles,
209: undef,undef,undef,undef,\@codetitles));
1.28 raeburn 210: $filter{'domainfilter'} = $dom;
211: my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,
1.56 raeburn 212: \%filter,$numtitles,undef,
213: undef,undef,\@codetitles);
1.46 raeburn 214: &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
1.28 raeburn 215: %courses);
1.1 raeburn 216: return;
217: }
218:
1.28 raeburn 219: sub print_modification_menu {
1.48 raeburn 220: my ($r,$cdesc,$domdesc,$dom,$type) = @_;
221: &print_header($r,$type);
1.61 raeburn 222: my ($ccrole,$categorytitle,$setquota_text,$setuploadquota_text,$setparams_text,$cat_text);
1.48 raeburn 223: if ($type eq 'Community') {
224: $ccrole = 'co';
225: } else {
226: $ccrole = 'cc';
1.61 raeburn 227: }
1.48 raeburn 228: if ($type eq 'Community') {
1.54 bisitz 229: $categorytitle = 'View/Modify Community Settings';
1.48 raeburn 230: $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
1.61 raeburn 231: $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a community via Content Editor.');
1.48 raeburn 232: $setparams_text = 'View/Modify community owner';
233: $cat_text = 'View/Modify catalog settings for community';
234: } else {
1.54 bisitz 235: $categorytitle = 'View/Modify Course Settings';
1.48 raeburn 236: $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
1.61 raeburn 237: $setuploadquota_text = &mt('Disk space allocated for storage of content uploaded directly to a course via Content Editor.');
1.60 raeburn 238: if (&showcredits($dom)) {
239: $setparams_text = 'View/Modify course owner, institutional code, and default authentication and credits';
240: } else {
241: $setparams_text = 'View/Modify course owner, institutional code, and default authentication';
242: }
1.57 raeburn 243: $cat_text = 'View/Modify catalog settings for course';
1.48 raeburn 244: }
1.57 raeburn 245: my $anon_text = 'Responder threshold required to display anonymous survey submissions';
1.54 bisitz 246:
1.38 raeburn 247: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
1.49 raeburn 248: my @additional_params = &catalog_settable($domconf{'coursecategories'},$type);
1.54 bisitz 249:
250: sub phaseurl {
251: my $phase = shift;
252: return "javascript:changePage(document.menu,'$phase')"
1.38 raeburn 253: }
1.54 bisitz 254: my @menu =
255: ({ categorytitle => $categorytitle,
256: items => [
257: {
258: linktext => $setparams_text,
259: url => &phaseurl('setparms'),
260: permission => 1,
261: #help => '',
1.55 bisitz 262: icon => 'crsconf.png',
1.54 bisitz 263: linktitle => ''
264: },
265: {
1.61 raeburn 266: linktext => 'View/Modify quotas for group portfolio files, and for uploaded content.',
1.54 bisitz 267: url => &phaseurl('setquota'),
268: permission => 1,
269: #help => '',
1.55 bisitz 270: icon => 'groupportfolioquota.png',
1.54 bisitz 271: linktitle => ''
272: },
273: {
1.57 raeburn 274: linktext => 'View/Modify responders threshold for anonymous survey submissions display',
275: url => &phaseurl('setanon'),
276: permission => 1,
277: #help => '',
278: icon => 'anonsurveythreshold.png',
279: linktitle => ''
280: },
281: {
1.54 bisitz 282: linktext => $cat_text,
283: url => &phaseurl('catsettings'),
284: permission => (@additional_params > 0),
285: #help => '',
1.55 bisitz 286: icon => 'ccatconf.png',
1.54 bisitz 287: linktitle => ''
288: },
289: {
290: linktext => 'Display current settings for automated enrollment',
291: url => &phaseurl('viewparms'),
292: permission => ($type ne 'Community'),
293: #help => '',
1.55 bisitz 294: icon => 'roles.png',
1.54 bisitz 295: linktitle => ''
296: },
297: ]
298: },
1.48 raeburn 299: );
1.54 bisitz 300:
301: my $menu_html =
302: '<h3>'
303: .&mt('View/Modify settings for: [_1]',
304: '<span class="LC_nobreak">'.$cdesc.'</span>')
305: .'</h3>'."\n".'<p>';
1.48 raeburn 306: if ($type eq 'Community') {
307: $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:');
308: } else {
309: $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:');
310: }
1.54 bisitz 311: $menu_html .= '</p>'."\n".'<ul>';
1.48 raeburn 312: if ($type eq 'Community') {
313: $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>';
314: } else {
315: $menu_html .= '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'.
316: '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>';
1.60 raeburn 317: if (&showcredits($dom)) {
318: $menu_html .= '<li>'.&mt('Default credits earned by student on course completion.').'</li>';
319: }
1.48 raeburn 320: }
1.57 raeburn 321: $menu_html .= '<li>'.$setquota_text.'</li>'.
1.61 raeburn 322: '<li>'.$setuploadquota_text.'</li>'.
1.57 raeburn 323: '<li>'.$anon_text.'</li>'."\n";
1.38 raeburn 324: foreach my $item (@additional_params) {
1.48 raeburn 325: if ($type eq 'Community') {
326: if ($item eq 'togglecats') {
1.54 bisitz 327: $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).','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
1.48 raeburn 328: } elsif ($item eq 'categorize') {
1.54 bisitz 329: $menu_html .= ' <li>'.&mt('Manual cataloging of a community (although can be [_1]configured[_2] to be modifiable by a Coordinator in community context).','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
1.48 raeburn 330: }
331: } else {
332: if ($item eq 'togglecats') {
1.54 bisitz 333: $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).','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
1.48 raeburn 334: } elsif ($item eq 'categorize') {
1.54 bisitz 335: $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).','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
1.48 raeburn 336: }
1.38 raeburn 337: }
338: }
1.54 bisitz 339: $menu_html .=
340: ' </ul>'
341: .'<form name="menu" method="post" action="/adm/modifycourse">'
342: ."\n"
343: .&hidden_form_elements();
1.28 raeburn 344:
345: $r->print($menu_html);
1.54 bisitz 346: $r->print(&Apache::lonhtmlcommon::generate_menu(@menu));
347: $r->print('</form>');
1.28 raeburn 348: return;
349: }
350:
1.37 raeburn 351: sub print_ccrole_selected {
1.48 raeburn 352: my ($r,$type) = @_;
353: &print_header($r,$type);
1.37 raeburn 354: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
355: $r->print('<form name="ccrole" method="post" action="/adm/roles">
356: <input type="hidden" name="selectrole" value="1" />
357: <input type="hidden" name="newrole" value="cc./'.$cdom.'/'.$cnum.'" />
358: </form>');
359: }
360:
1.28 raeburn 361: sub print_settings_display {
362: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
363: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.48 raeburn 364: my %longtype = &course_settings_descrip($type);
1.28 raeburn 365: my %lt = &Apache::lonlocal::texthash(
1.48 raeburn 366: 'valu' => 'Current value',
367: 'cour' => 'Current settings are:',
368: 'cose' => "Settings which control auto-enrollment using classlists from your institution's student information system fall into two groups:",
369: 'dcon' => 'Modifiable only by Domain Coordinator',
370: 'back' => 'Pick another action',
1.28 raeburn 371: );
1.48 raeburn 372: my $ccrole = 'cc';
373: if ($type eq 'Community') {
374: $ccrole = 'co';
375: }
376: my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.28 raeburn 377: my $dctitle = &Apache::lonnet::plaintext('dc');
1.60 raeburn 378: my @modifiable_params = &get_dc_settable($type,$cdom);
1.48 raeburn 379: my ($internals,$accessdates) = &autoenroll_keys();
380: my @items;
381: if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
382: @items = (@{$internals},@{$accessdates});
383: }
1.28 raeburn 384: my $disp_table = &Apache::loncommon::start_data_table()."\n".
385: &Apache::loncommon::start_data_table_header_row()."\n".
1.48 raeburn 386: "<th> </th>\n".
1.28 raeburn 387: "<th>$lt{'valu'}</th>\n".
388: "<th>$lt{'dcon'}</th>\n".
389: &Apache::loncommon::end_data_table_header_row()."\n";
1.48 raeburn 390: foreach my $item (@items) {
1.28 raeburn 391: $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
1.48 raeburn 392: "<td><b>$longtype{$item}</b></td>\n".
393: "<td>$enrollvar{$item}</td>\n";
394: if (grep(/^\Q$item\E$/,@modifiable_params)) {
1.50 raeburn 395: $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n";
1.28 raeburn 396: } else {
1.48 raeburn 397: $disp_table .= '<td align="right">'.&mt('No').'</td>'."\n";
1.28 raeburn 398: }
399: $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
1.3 raeburn 400: }
1.28 raeburn 401: $disp_table .= &Apache::loncommon::end_data_table()."\n";
1.48 raeburn 402: &print_header($r,$type);
403: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
404: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
405: '=1&destinationurl=/adm/populate','&<>"');
406: $r->print('<h3>'.&mt('Current automated enrollment settings for:').
407: ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'.
408: '<form action="/adm/modifycourse" method="post" name="viewparms">'."\n".
409: '<p>'.$lt{'cose'}.'<ul>'.
1.60 raeburn 410: '<li>'.&mt('Settings modifiable by a [_1] via the [_2]Automated Enrollment Manager[_3] in a course.',$cctitle,'<a href="'.$escuri.'">','</a>').'</li>');
411: if (&showcredits($cdom)) {
1.64 ! raeburn 412: $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, and default authentication and credits[_3].',$dctitle,'<a href="javascript:changePage(document.viewparms,'."'setparms'".');">','</a>')."\n");
1.60 raeburn 413: } else {
414: $r->print('<li>'.&mt('Settings modifiable by a [_1] via [_2]View/Modify course owner, institutional code, and default authentication[_3].',$dctitle,'<a href="javascript:changePage(document.viewparms,'."'setparms'".');">','</a>')."\n");
415: }
416: $r->print('</li></ul></p>'.
1.48 raeburn 417: '<p>'.$lt{'cour'}.'</p><p>'.$disp_table.'</p><p>'.
418: '<a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>'."\n".
419: &hidden_form_elements().
420: '</p></form>'
421: );
1.28 raeburn 422: }
1.3 raeburn 423:
1.28 raeburn 424: sub print_setquota {
425: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
1.61 raeburn 426: my $lctype = lc($type);
427: my $headline = &mt("Set disk space quotas for $lctype: [_1]",
428: '<span class="LC_nobreak">'.$cdesc.'</span>');
1.28 raeburn 429: my %lt = &Apache::lonlocal::texthash(
1.61 raeburn 430: 'gpqu' => 'Disk space for storage of group portfolio files',
431: 'upqu' => 'Disk space for storage of content directly uploaded to course via Content Editor',
1.42 schafran 432: 'modi' => 'Save',
1.48 raeburn 433: 'back' => 'Pick another action',
1.28 raeburn 434: );
1.61 raeburn 435: my %staticdefaults = (
436: coursequota => 20,
437: uploadquota => 500,
438: );
439: my %settings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota','internal.instcode'],
440: $cdom,$cnum);
1.28 raeburn 441: my $coursequota = $settings{'internal.coursequota'};
1.61 raeburn 442: my $uploadquota = $settings{'internal.uploadquota'};
1.28 raeburn 443: if ($coursequota eq '') {
1.61 raeburn 444: $coursequota = $staticdefaults{'coursequota'};
445: }
446: if ($uploadquota eq '') {
447: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
448: if ($type eq 'Community') {
449: $uploadquota = $domdefs{$lctype.'quota'};
450: } elsif ($settings{'internal.instcode'}) {
451: $uploadquota = $domdefs{'officialquota'};
452: } else {
453: $uploadquota = $domdefs{'unofficialquota'};
454: }
455: if ($uploadquota eq '') {
456: $uploadquota = $staticdefaults{'uploadquota'};
457: }
1.3 raeburn 458: }
1.48 raeburn 459: &print_header($r,$type);
1.28 raeburn 460: my $hidden_elements = &hidden_form_elements();
1.61 raeburn 461: my $porthelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
462: my $uploadhelpitem = &Apache::loncommon::help_open_topic('Modify_Course_Upload_Quota');
1.28 raeburn 463: $r->print(<<ENDDOCUMENT);
1.57 raeburn 464: <form action="/adm/modifycourse" method="post" name="setquota" onsubmit="return verify_quota();">
1.61 raeburn 465: <h3>$headline</h3>
466: <p><span class="LC_nobreak">
467: $porthelpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" /> MB
468: </span>
469: <br />
470: <span class="LC_nobreak">
471: $uploadhelpitem $lt{'upqu'}: <input type="text" size="4" name="uploadquota" value="$uploadquota" /> MB
472: </span>
473: </p>
1.28 raeburn 474: <p>
1.57 raeburn 475: <input type="submit" value="$lt{'modi'}" />
1.28 raeburn 476: </p>
477: $hidden_elements
478: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
479: </form>
480: ENDDOCUMENT
481: return;
482: }
1.3 raeburn 483:
1.57 raeburn 484: sub print_set_anonsurvey_threshold {
485: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
486: my %lt = &Apache::lonlocal::texthash(
487: 'resp' => 'Responder threshold for anonymous survey submissions display:',
488: 'sufa' => 'Anonymous survey submissions displayed when responders exceeds',
489: 'modi' => 'Save',
490: 'back' => 'Pick another action',
491: );
492: my %settings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
493: my $threshold = $settings{'internal.anonsurvey_threshold'};
494: if ($threshold eq '') {
495: my %domconfig =
496: &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
497: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
498: $threshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
499: if ($threshold eq '') {
500: $threshold = 10;
501: }
502: } else {
503: $threshold = 10;
504: }
505: }
506: &print_header($r,$type);
507: my $hidden_elements = &hidden_form_elements();
508: my $helpitem = &Apache::loncommon::help_open_topic('Modify_Anonsurvey_Threshold');
509: $r->print(<<ENDDOCUMENT);
510: <form action="/adm/modifycourse" method="post" name="setanon" onsubmit="return verify_anon_threshold();">
511: <h3>$lt{'resp'} <span class="LC_nobreak">$cdesc</span></h3>
512: <p>
513: $helpitem $lt{'sufa'}: <input type="text" size="4" name="threshold" value="$threshold" />
514: <input type="submit" value="$lt{'modi'}" />
515: </p>
516: $hidden_elements
517: <a href="javascript:changePage(document.setanon,'menu')">$lt{'back'}</a>
518: </form>
519: ENDDOCUMENT
520: return;
521: }
522:
1.38 raeburn 523: sub print_catsettings {
1.48 raeburn 524: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
525: &print_header($r,$type);
1.38 raeburn 526: my %lt = &Apache::lonlocal::texthash(
1.48 raeburn 527: 'back' => 'Pick another action',
528: 'catset' => 'Catalog Settings for Course',
529: 'visi' => 'Visibility in Course/Community Catalog',
530: 'exclude' => 'Exclude from course catalog:',
531: 'categ' => 'Categorize Course',
532: 'assi' => 'Assign one or more categories and/or subcategories to this course.'
1.38 raeburn 533: );
1.48 raeburn 534: if ($type eq 'Community') {
535: $lt{'catset'} = &mt('Catalog Settings for Community');
536: $lt{'exclude'} = &mt('Exclude from course catalog');
537: $lt{'categ'} = &mt('Categorize Community');
1.49 raeburn 538: $lt{'assi'} = &mt('Assign one or more subcategories to this community.');
1.48 raeburn 539: }
1.38 raeburn 540: $r->print('<form action="/adm/modifycourse" method="post" name="catsettings">'.
1.48 raeburn 541: '<h3>'.$lt{'catset'}.' <span class="LC_nobreak">'.$cdesc.'</span></h3>');
1.38 raeburn 542: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49 raeburn 543: my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38 raeburn 544: if (@cat_params > 0) {
545: my %currsettings =
546: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
547: if (grep(/^togglecats$/,@cat_params)) {
548: my $excludeon = '';
549: my $excludeoff = ' checked="checked" ';
550: if ($currsettings{'hidefromcat'} eq 'yes') {
551: $excludeon = $excludeoff;
552: $excludeoff = '';
553: }
1.48 raeburn 554: $r->print('<br /><h4>'.$lt{'visi'}.'</h4>'.
555: $lt{'exclude'}.
556: ' <label><input name="hidefromcat" type="radio" value="yes" '.$excludeon.' />'.&mt('Yes').'</label> <label><input name="hidefromcat" type="radio" value="" '.$excludeoff.' />'.&mt('No').'</label><br /><p>');
557: if ($type eq 'Community') {
558: $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."));
559: } else {
560: $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>'.
561: '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code.').'</li>'.
562: '<li>'.&mt('The course has been categorized using at least one of the course categories defined for the domain.').'</li></ul>');
563: }
564: $r->print('</ul></p>');
1.38 raeburn 565: }
566: if (grep(/^categorize$/,@cat_params)) {
1.48 raeburn 567: $r->print('<br /><h4>'.$lt{'categ'}.'</h4>');
1.38 raeburn 568: if (ref($domconf{'coursecategories'}) eq 'HASH') {
569: my $cathash = $domconf{'coursecategories'}{'cats'};
570: if (ref($cathash) eq 'HASH') {
1.48 raeburn 571: $r->print($lt{'assi'}.'<br /><br />'.
1.38 raeburn 572: &Apache::loncommon::assign_categories_table($cathash,
1.49 raeburn 573: $currsettings{'categories'},$type));
1.38 raeburn 574: } else {
575: $r->print(&mt('No categories defined for this domain'));
576: }
577: } else {
578: $r->print(&mt('No categories defined for this domain'));
579: }
1.48 raeburn 580: unless ($type eq 'Community') {
581: $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>');
582: }
1.38 raeburn 583: }
1.48 raeburn 584: $r->print('<p><input type="button" name="chgcatsettings" value="'.
585: &mt('Save').'" onclick="javascript:changePage(document.catsettings,'."'processcat'".');" /></p>');
1.38 raeburn 586: } else {
1.48 raeburn 587: $r->print('<span class="LC_warning">');
588: if ($type eq 'Community') {
589: $r->print(&mt('Catalog settings in this domain are set in community context via "Community Configuration".'));
590: } else {
591: $r->print(&mt('Catalog settings in this domain are set in course context via "Course Configuration".'));
592: }
593: $r->print('</span><br /><br />'."\n".
1.38 raeburn 594: '<a href="javascript:changePage(document.catsettings,'."'menu'".');">'.
595: $lt{'back'}.'</a>');
596: }
597: $r->print(&hidden_form_elements().'</form>'."\n");
598: return;
599: }
600:
1.28 raeburn 601: sub print_course_modification_page {
1.48 raeburn 602: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
1.2 raeburn 603: my %lt=&Apache::lonlocal::texthash(
604: 'actv' => "Active",
605: 'inac' => "Inactive",
606: 'ownr' => "Owner",
607: 'name' => "Name",
1.26 raeburn 608: 'unme' => "Username:Domain",
1.2 raeburn 609: 'stus' => "Status",
1.48 raeburn 610: 'nocc' => 'There is currently no owner set for this course.',
1.32 raeburn 611: 'gobt' => "Save",
1.2 raeburn 612: );
1.48 raeburn 613: my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname);
614: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
615: if ($type eq 'Community') {
616: $ccrole = 'co';
617: $lt{'nocc'} = &mt('There is currently no owner set for this community.');
618: } else {
619: $ccrole ='cc';
620: ($javascript_validations,$authenitems) = &gather_authenitems($cdom,\%enrollvar);
621: }
622: $ccname = &Apache::lonnet::plaintext($ccrole,$type);
623: my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,'','',[$ccrole]);
624: my (@local_ccs,%cc_status,%pname);
625: foreach my $item (keys(%roleshash)) {
626: my ($uname,$udom) = split(/:/,$item);
627: if (!grep(/^\Q$uname\E:\Q$udom\E$/,@local_ccs)) {
628: push(@local_ccs,$uname.':'.$udom);
629: $pname{$uname.':'.$udom} = &Apache::loncommon::plainname($uname,$udom);
630: $cc_status{$uname.':'.$udom} = $lt{'actv'};
1.1 raeburn 631: }
632: }
1.48 raeburn 633: if (($enrollvar{'courseowner'} ne '') &&
634: (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs))) {
635: push(@local_ccs,$enrollvar{'courseowner'});
1.26 raeburn 636: my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
637: $pname{$enrollvar{'courseowner'}} =
638: &Apache::loncommon::plainname($owneruname,$ownerdom);
1.48 raeburn 639: my $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
640: $cdom,$cnum,$ccrole);
1.19 raeburn 641: if ($active_cc eq 'active') {
1.2 raeburn 642: $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1 raeburn 643: } else {
1.2 raeburn 644: $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1 raeburn 645: }
646: }
1.48 raeburn 647: @local_ccs = sort(@local_ccs);
648: if (@local_ccs == 0) {
649: $ownertable = $lt{'nocc'};
650: } else {
651: my $numlocalcc = scalar(@local_ccs);
652: $ownertable = '<input type="hidden" name="numlocalcc" value="'.$numlocalcc.'" />'.
653: &Apache::loncommon::start_data_table()."\n".
654: &Apache::loncommon::start_data_table_header_row()."\n".
655: '<th>'.$lt{'ownr'}.'</th>'.
656: '<th>'.$lt{'name'}.'</th>'.
657: '<th>'.$lt{'unme'}.'</th>'.
658: '<th>'.$lt{'stus'}.'</th>'.
659: &Apache::loncommon::end_data_table_header_row()."\n";
660: foreach my $cc (@local_ccs) {
661: $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
662: if ($cc eq $enrollvar{'courseowner'}) {
663: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked" /></td>'."\n";
664: } else {
665: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" /></td>'."\n";
666: }
667: $ownertable .=
668: '<td>'.$pname{$cc}.'</td>'."\n".
669: '<td>'.$cc.'</td>'."\n".
670: '<td>'.$cc_status{$cc}.' '.$ccname.'</td>'."\n".
671: &Apache::loncommon::end_data_table_row()."\n";
672: }
673: $ownertable .= &Apache::loncommon::end_data_table();
674: }
675: &print_header($r,$type,$javascript_validations);
676: my $dctitle = &Apache::lonnet::plaintext('dc');
677: my $mainheader = &modifiable_only_title($type);
678: my $hidden_elements = &hidden_form_elements();
679: $r->print('<form action="/adm/modifycourse" method="post" name="'.$env{'form.phase'}.'">'."\n".
680: '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3><p>'.
681: &Apache::lonhtmlcommon::start_pick_box());
682: if ($type eq 'Community') {
683: $r->print(&Apache::lonhtmlcommon::row_title(
684: &Apache::loncommon::help_open_topic('Modify_Community_Owner').
685: ' '.&mt('Community Owner'))."\n");
686: } else {
687: $r->print(&Apache::lonhtmlcommon::row_title(
688: &Apache::loncommon::help_open_topic('Modify_Course_Instcode').
689: ' '.&mt('Course Code'))."\n".
690: '<input type="text" size="10" name="coursecode" value="'.$enrollvar{'coursecode'}.'" />'.
1.60 raeburn 691: &Apache::lonhtmlcommon::row_closure());
692: if (&showcredits($cdom)) {
693: $r->print(&Apache::lonhtmlcommon::row_title(
694: &Apache::loncommon::help_open_topic('Modify_Course_Credithours').
695: ' '.&mt('Credits (students)'))."\n".
696: '<input type="text" size="3" name="defaultcredits" value="'.$enrollvar{'defaultcredits'}.'" />'.
697: &Apache::lonhtmlcommon::row_closure());
698: }
699: $r->print(&Apache::lonhtmlcommon::row_title(
700: &Apache::loncommon::help_open_topic('Modify_Course_Defaultauth').
701: ' '.&mt('Default Authentication method'))."\n".
702: $authenitems."\n".
703: &Apache::lonhtmlcommon::row_closure().
704: &Apache::lonhtmlcommon::row_title(
705: &Apache::loncommon::help_open_topic('Modify_Course_Owner').
1.48 raeburn 706: ' '.&mt('Course Owner'))."\n");
707: }
708: $r->print($ownertable."\n".&Apache::lonhtmlcommon::row_closure(1).
709: &Apache::lonhtmlcommon::end_pick_box().'</p><p>'.$hidden_elements.
710: '<input type="button" onclick="javascript:changePage(this.form,'."'processparms'".');');
711: if ($type eq 'Community') {
712: $r->print('this.form.submit();"');
713: } else {
714: $r->print('javascript:verify_message(this.form);"');
715: }
1.60 raeburn 716: $r->print(' value="'.$lt{'gobt'}.'" /></p></form>');
1.48 raeburn 717: return;
718: }
719:
720: sub modifiable_only_title {
721: my ($type) = @_;
722: my $dctitle = &Apache::lonnet::plaintext('dc');
723: if ($type eq 'Community') {
724: return &mt('Community settings modifiable only by [_1] for:',$dctitle);
725: } else {
726: return &mt('Course settings modifiable only by [_1] for:',$dctitle);
727: }
728: }
1.24 albertel 729:
1.48 raeburn 730: sub gather_authenitems {
731: my ($cdom,$enrollvar) = @_;
1.28 raeburn 732: my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
1.2 raeburn 733: my $curr_authtype = '';
734: my $curr_authfield = '';
1.48 raeburn 735: if (ref($enrollvar) eq 'HASH') {
736: if ($enrollvar->{'authtype'} =~ /^krb/) {
737: $curr_authtype = 'krb';
738: } elsif ($enrollvar->{'authtype'} eq 'internal' ) {
739: $curr_authtype = 'int';
740: } elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
741: $curr_authtype = 'loc';
742: }
1.2 raeburn 743: }
744: unless ($curr_authtype eq '') {
745: $curr_authfield = $curr_authtype.'arg';
1.33 raeburn 746: }
1.48 raeburn 747: my $javascript_validations =
748: &Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,
749: $curr_authtype,$curr_authfield);
1.35 raeburn 750: my %param = ( formname => 'document.'.$env{'form.phase'},
1.48 raeburn 751: kerb_def_dom => $krbdefdom,
752: kerb_def_auth => $krbdef,
1.2 raeburn 753: mode => 'modifycourse',
754: curr_authtype => $curr_authtype,
1.48 raeburn 755: curr_autharg => $enrollvar->{'autharg'}
756: );
1.32 raeburn 757: my (%authform,$authenitems);
758: $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
759: $authform{'int'} = &Apache::loncommon::authform_internal(%param);
760: $authform{'loc'} = &Apache::loncommon::authform_local(%param);
761: foreach my $item ('krb','int','loc') {
762: if ($authform{$item} ne '') {
763: $authenitems .= $authform{$item}.'<br />';
764: }
1.1 raeburn 765: }
1.48 raeburn 766: return($javascript_validations,$authenitems);
1.1 raeburn 767: }
768:
769: sub modify_course {
1.30 raeburn 770: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1.48 raeburn 771: my %longtype = &course_settings_descrip($type);
1.50 raeburn 772: my @items = ('internal.courseowner','description','internal.co-owners',
773: 'internal.pendingco-owners');
1.48 raeburn 774: unless ($type eq 'Community') {
775: push(@items,('internal.coursecode','internal.authtype','internal.autharg',
776: 'internal.sectionnums','internal.crosslistings'));
1.60 raeburn 777: if (&showcredits($cdom)) {
778: push(@items,'internal.defaultcredits');
779: }
1.1 raeburn 780: }
1.48 raeburn 781: my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
782: my $description = $settings{'description'};
1.60 raeburn 783: my ($ccrole,$response,$chgresponse,$nochgresponse,$reply,%currattr,%newattr,
784: %cenv,%changed,@changes,@nochanges,@sections,@xlists,@warnings);
785: my @modifiable_params = &get_dc_settable($type,$cdom);
1.28 raeburn 786: foreach my $param (@modifiable_params) {
1.48 raeburn 787: $currattr{$param} = $settings{'internal.'.$param};
1.1 raeburn 788: }
1.48 raeburn 789: if ($type eq 'Community') {
790: %changed = ( owner => 0 );
791: $ccrole = 'co';
792: } else {
793: %changed = ( code => 0,
794: owner => 0,
795: );
796: $ccrole = 'cc';
797: unless ($settings{'internal.sectionnums'} eq '') {
798: if ($settings{'internal.sectionnums'} =~ m/,/) {
799: @sections = split/,/,$settings{'internal.sectionnums'};
800: } else {
801: $sections[0] = $settings{'internal.sectionnums'};
802: }
803: }
1.60 raeburn 804: unless ($settings{'internal.crosslistings'} eq '') {
1.48 raeburn 805: if ($settings{'internal.crosslistings'} =~ m/,/) {
806: @xlists = split/,/,$settings{'internal.crosslistings'};
807: } else {
808: $xlists[0] = $settings{'internal.crosslistings'};
809: }
810: }
811: if ($env{'form.login'} eq 'krb') {
812: $newattr{'authtype'} = $env{'form.login'};
813: $newattr{'authtype'} .= $env{'form.krbver'};
814: $newattr{'autharg'} = $env{'form.krbarg'};
815: } elsif ($env{'form.login'} eq 'int') {
816: $newattr{'authtype'} ='internal';
817: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
818: $newattr{'autharg'} = $env{'form.intarg'};
819: }
820: } elsif ($env{'form.login'} eq 'loc') {
821: $newattr{'authtype'} = 'localauth';
822: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
823: $newattr{'autharg'} = $env{'form.locarg'};
824: }
825: }
826: if ( $newattr{'authtype'}=~ /^krb/) {
827: if ($newattr{'autharg'} eq '') {
828: push(@warnings,
829: &mt('As you did not include the default Kerberos domain'
1.45 bisitz 830: .' to be used for authentication in this class, the'
831: .' institutional data used by the automated'
832: .' enrollment process must include the Kerberos'
1.48 raeburn 833: .' domain for each new student.'));
834: }
835: }
836:
837: if ( exists($env{'form.coursecode'}) ) {
838: $newattr{'coursecode'}=$env{'form.coursecode'};
839: unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
840: $changed{'code'} = 1;
841: }
1.1 raeburn 842: }
1.60 raeburn 843:
844: if (&showcredits($cdom) && exists($env{'form.defaultcredits'})) {
845: $newattr{'defaultcredits'} =~ s/[^\d\.]//g;
846: $newattr{'defaultcredits'}=$env{'form.defaultcredits'};
847: }
848:
1.1 raeburn 849: }
850:
1.16 albertel 851: if ( exists($env{'form.courseowner'}) ) {
852: $newattr{'courseowner'}=$env{'form.courseowner'};
1.14 raeburn 853: unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
1.38 raeburn 854: $changed{'owner'} = 1;
1.1 raeburn 855: }
856: }
1.48 raeburn 857:
1.50 raeburn 858: if ($changed{'owner'} || $changed{'code'}) {
1.38 raeburn 859: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
860: undef,undef,'.');
861: if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
1.48 raeburn 862: if ($changed{'code'}) {
863: $crsinfo{$env{'form.pickedcourse'}}{'inst_code'} = $env{'form.coursecode'};
864: }
865: if ($changed{'owner'}) {
866: $crsinfo{$env{'form.pickedcourse'}}{'owner'} = $env{'form.courseowner'};
867: }
1.38 raeburn 868: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
869: my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
1.50 raeburn 870: if ($putres eq 'ok') {
871: &update_coowners($cdom,$cnum,$chome,\%settings,\%newattr);
872: }
1.38 raeburn 873: }
1.14 raeburn 874: }
1.28 raeburn 875: foreach my $param (@modifiable_params) {
876: if ($currattr{$param} eq $newattr{$param}) {
877: push(@nochanges,$param);
1.1 raeburn 878: } else {
1.48 raeburn 879: $cenv{'internal.'.$param} = $newattr{$param};
1.28 raeburn 880: push(@changes,$param);
1.1 raeburn 881: }
882: }
883: if (@changes > 0) {
1.62 bisitz 884: $chgresponse = &mt('The following settings have been changed:').'<br/><ul>';
1.1 raeburn 885: }
1.48 raeburn 886: if (@nochanges > 0) {
1.62 bisitz 887: $nochgresponse = &mt('The following settings remain unchanged:').'<br/><ul>';
1.1 raeburn 888: }
1.33 raeburn 889: if (@changes > 0) {
1.28 raeburn 890: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1.1 raeburn 891: if ($putreply !~ /^ok$/) {
1.48 raeburn 892: $response = '<p class="LC_error">'.
893: &mt('There was a problem processing your requested changes.').'<br />';
894: if ($type eq 'Community') {
895: $response .= &mt('Settings for this community have been left unchanged.');
896: } else {
897: $response .= &mt('Settings for this course have been left unchanged.');
898: }
899: $response .= '<br/>'.&mt('Error: ').$putreply.'</p>';
1.1 raeburn 900: } else {
1.28 raeburn 901: foreach my $attr (@modifiable_params) {
1.48 raeburn 902: if (grep/^\Q$attr\E$/,@changes) {
903: $chgresponse .= '<li>'.$longtype{$attr}.' '.&mt('now set to:').' "'.$newattr{$attr}.'".</li>';
1.1 raeburn 904: } else {
1.48 raeburn 905: $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to:').' "'.$currattr{$attr}.'".</li>';
1.1 raeburn 906: }
907: }
1.48 raeburn 908: if (($type ne 'Community') && ($changed{'code'} || $changed{'owner'})) {
1.1 raeburn 909: if ( $newattr{'courseowner'} eq '') {
1.48 raeburn 910: push(@warnings,&mt('There is no owner associated with this LON-CAPA course.').
911: '<br />'.&mt('If automated enrollment at your institution requires validation of course owners, automated enrollment will fail.'));
1.1 raeburn 912: } else {
1.59 raeburn 913: my %crsenv = &Apache::lonnet::get('environment',['internal.co-owners'],$cdom,$cnum);
914: my $coowners = $crsenv{'internal.co-owners'};
1.1 raeburn 915: if (@sections > 0) {
1.38 raeburn 916: if ($changed{'code'}) {
1.2 raeburn 917: foreach my $sec (@sections) {
918: if ($sec =~ m/^(.+):/) {
1.48 raeburn 919: my $instsec = $1;
1.8 raeburn 920: my $inst_course_id = $newattr{'coursecode'}.$1;
1.28 raeburn 921: my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
1.7 raeburn 922: if ($course_check eq 'ok') {
1.58 raeburn 923: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners);
1.48 raeburn 924: unless ($outcome eq 'ok') {
925:
1.53 raeburn 926: 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 927: }
928: } else {
1.53 raeburn 929: 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 930: }
931: } else {
1.48 raeburn 932: 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 933: }
934: }
1.38 raeburn 935: } elsif ($changed{'owner'}) {
1.4 raeburn 936: foreach my $sec (@sections) {
937: if ($sec =~ m/^(.+):/) {
1.48 raeburn 938: my $instsec = $1;
939: my $inst_course_id = $newattr{'coursecode'}.$instsec;
1.58 raeburn 940: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'},$coowners);
1.4 raeburn 941: unless ($outcome eq 'ok') {
1.53 raeburn 942: 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 943: }
944: } else {
1.53 raeburn 945: 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 946: }
947: }
948: }
1.1 raeburn 949: } else {
1.53 raeburn 950: 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 951: }
1.38 raeburn 952: if ( (@xlists > 0) && ($changed{'owner'}) ) {
1.1 raeburn 953: foreach my $xlist (@xlists) {
954: if ($xlist =~ m/^(.+):/) {
1.48 raeburn 955: my $instxlist = $1;
1.58 raeburn 956: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$instxlist,$newattr{'courseowner'},$coowners);
1.1 raeburn 957: unless ($outcome eq 'ok') {
1.48 raeburn 958: 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 959: }
1.28 raeburn 960: }
1.1 raeburn 961: }
962: }
963: }
964: }
965: }
1.2 raeburn 966: } else {
1.28 raeburn 967: foreach my $attr (@modifiable_params) {
1.48 raeburn 968: $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to').' "'.$currattr{$attr}.'".</li>';
1.2 raeburn 969: }
1.1 raeburn 970: }
971:
972: if (@changes > 0) {
973: $chgresponse .= "</ul><br/><br/>";
974: }
975: if (@nochanges > 0) {
976: $nochgresponse .= "</ul><br/><br/>";
977: }
1.48 raeburn 978: my ($warning,$numwarnings);
979: my $numwarnings = scalar(@warnings);
980: if ($numwarnings) {
981: $warning = &mt('The following [quant,_1,warning was,warnings were] generated when applying your changes to automated enrollment:',$numwarnings).'<p><ul>';
982: foreach my $warn (@warnings) {
983: $warning .= '<li><span class="LC_warning">'.$warn.'</span></li>';
984: }
985: $warning .= '</ul></p>';
1.1 raeburn 986: }
1.48 raeburn 987: if ($response) {
988: $reply = $response;
989: } else {
1.1 raeburn 990: $reply = $chgresponse.$nochgresponse.$warning;
991: }
1.48 raeburn 992: &print_header($r,$type);
993: my $mainheader = &modifiable_only_title($type);
994: $reply = '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n".
995: '<p>'.$reply.'</p>'."\n".
1.28 raeburn 996: '<form action="/adm/modifycourse" method="post" name="processparms">'.
997: &hidden_form_elements().
1.48 raeburn 998: '<a href="javascript:changePage(document.processparms,'."'menu'".')">'.
999: &mt('Pick another action').'</a>';
1000: if ($numwarnings) {
1001: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
1002: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
1003: '=1&destinationurl=/adm/populate','&<>"');
1004:
1005: $reply .= '<br /><a href="'.$escuri.'">'.
1006: &mt('Go to Automated Enrollment Manager for course').'</a>';
1007: }
1008: $reply .= '</form>';
1.3 raeburn 1009: $r->print($reply);
1.28 raeburn 1010: return;
1011: }
1012:
1.50 raeburn 1013: sub update_coowners {
1014: my ($cdom,$cnum,$chome,$settings,$newattr) = @_;
1015: return unless ((ref($settings) eq 'HASH') && (ref($newattr) eq 'HASH'));
1016: my %designhash = &Apache::loncommon::get_domainconf($cdom);
1017: my (%cchash,$autocoowners);
1018: if ($designhash{$cdom.'.autoassign.co-owners'}) {
1019: $autocoowners = 1;
1020: %cchash = &Apache::lonnet::get_my_roles($cnum,$cdom,undef,undef,['cc']);
1021: }
1022: if ($settings->{'internal.courseowner'} ne $newattr->{'courseowner'}) {
1023: my $oldowner_to_coowner;
1.51 raeburn 1024: my @types = ('co-owners');
1.50 raeburn 1025: if (($newattr->{'coursecode'}) && ($autocoowners)) {
1026: my $oldowner = $settings->{'internal.courseowner'};
1027: if ($cchash{$oldowner.':cc'}) {
1.51 raeburn 1028: my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$oldowner);
1029: if ($result eq 'valid') {
1030: if ($settings->{'internal.co-owner'}) {
1031: my @current = split(',',$settings->{'internal.co-owners'});
1032: unless (grep(/^\Q$oldowner\E$/,@current)) {
1033: $oldowner_to_coowner = 1;
1034: }
1035: } else {
1.50 raeburn 1036: $oldowner_to_coowner = 1;
1037: }
1038: }
1039: }
1.51 raeburn 1040: } else {
1041: push(@types,'pendingco-owners');
1.50 raeburn 1042: }
1.51 raeburn 1043: foreach my $type (@types) {
1.50 raeburn 1044: if ($settings->{'internal.'.$type}) {
1045: my @current = split(',',$settings->{'internal.'.$type});
1046: my $newowner = $newattr->{'courseowner'};
1047: my @newvalues = ();
1048: if (($newowner ne '') && (grep(/^\Q$newowner\E$/,@current))) {
1049: foreach my $person (@current) {
1050: unless ($person eq $newowner) {
1051: push(@newvalues,$person);
1052: }
1053: }
1054: } else {
1055: @newvalues = @current;
1056: }
1057: if ($oldowner_to_coowner) {
1058: push(@newvalues,$settings->{'internal.courseowner'});
1059: @newvalues = sort(@newvalues);
1060: }
1061: my $newownstr = join(',',@newvalues);
1062: if ($newownstr ne $settings->{'internal.'.$type}) {
1063: if ($type eq 'co-owners') {
1064: my $deleted = '';
1065: unless (@newvalues) {
1066: $deleted = 1;
1067: }
1068: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
1069: $deleted,@newvalues);
1070: } else {
1071: my $pendingcoowners;
1072: my $cid = $cdom.'_'.$cnum;
1073: if (@newvalues) {
1074: $pendingcoowners = join(',',@newvalues);
1075: my %pendinghash = (
1076: 'internal.pendingco-owners' => $pendingcoowners,
1077: );
1.52 raeburn 1078: my $putresult = &Apache::lonnet::put('environment',\%pendinghash,$cdom,$cnum);
1.50 raeburn 1079: if ($putresult eq 'ok') {
1080: if ($env{'course.'.$cid.'.num'} eq $cnum) {
1.52 raeburn 1081: &Apache::lonnet::appenv({'course.'.$cid.'.internal.pendingco-owners' => $pendingcoowners});
1.50 raeburn 1082: }
1083: }
1084: } else {
1085: my $delresult = &Apache::lonnet::del('environment',['internal.pendingco-owners'],$cdom,$cnum);
1086: if ($delresult eq 'ok') {
1087: if ($env{'course.'.$cid.'.internal.pendingco-owners'}) {
1088: &Apache::lonnet::delenv('course.'.$cid.'.internal.pendingco-owners');
1089: }
1090: }
1091: }
1092: }
1093: } elsif ($oldowner_to_coowner) {
1094: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
1095: $settings->{'internal.courseowner'});
1096:
1097: }
1098: } elsif ($oldowner_to_coowner) {
1099: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
1100: $settings->{'internal.courseowner'});
1101: }
1102: }
1103: }
1104: if ($settings->{'internal.coursecode'} ne $newattr->{'coursecode'}) {
1105: if ($newattr->{'coursecode'} ne '') {
1106: my %designhash = &Apache::loncommon::get_domainconf($cdom);
1107: if ($designhash{$cdom.'.autoassign.co-owners'}) {
1108: my @newcoowners = ();
1109: if ($settings->{'internal.co-owners'}) {
1.58 raeburn 1110: my @currcoown = split(',',$settings->{'internal.co-owners'});
1.50 raeburn 1111: my ($updatecoowners,$delcoowners);
1112: foreach my $person (@currcoown) {
1.51 raeburn 1113: my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$person);
1.50 raeburn 1114: if ($result eq 'valid') {
1115: push(@newcoowners,$person);
1116: }
1117: }
1118: foreach my $item (sort(keys(%cchash))) {
1119: my ($uname,$udom,$urole) = split(':',$item);
1.51 raeburn 1120: next if ($uname.':'.$udom eq $newattr->{'courseowner'});
1.50 raeburn 1121: unless (grep(/^\Q$uname\E:\Q$udom\E$/,@newcoowners)) {
1.51 raeburn 1122: my ($result,$desc) = &Apache::lonnet::auto_validate_instcode($cnum,$cdom,$newattr->{'coursecode'},$uname.':'.$udom);
1123: if ($result eq 'valid') {
1124: push(@newcoowners,$uname.':'.$udom);
1125: }
1.50 raeburn 1126: }
1127: }
1128: if (@newcoowners) {
1129: my $coowners = join(',',sort(@newcoowners));
1130: unless ($coowners eq $settings->{'internal.co-owners'}) {
1131: $updatecoowners = 1;
1132: }
1133: } else {
1134: $delcoowners = 1;
1135: }
1136: if ($updatecoowners || $delcoowners) {
1137: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,
1138: $delcoowners,@newcoowners);
1139: }
1140: } else {
1141: foreach my $item (sort(keys(%cchash))) {
1142: my ($uname,$udom,$urole) = split(':',$item);
1143: push(@newcoowners,$uname.':'.$udom);
1144: }
1145: if (@newcoowners) {
1146: &Apache::lonnet::store_coowners($cdom,$cnum,$chome,'',
1147: @newcoowners);
1148: }
1149: }
1150: }
1151: }
1152: }
1153: return;
1154: }
1155:
1.28 raeburn 1156: sub modify_quota {
1.48 raeburn 1157: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1158: &print_header($r,$type);
1.61 raeburn 1159: my $lctype = lc($type);
1160: my $headline = &mt("Disk space quotas for $lctype: [_1]",
1161: '<span class="LC_nobreak">'.$cdesc.'</span>');
1.48 raeburn 1162: $r->print('<form action="/adm/modifycourse" method="post" name="processquota">'."\n".
1.61 raeburn 1163: '<h3>'.$headline.'</h3>');
1164: my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
1165: my %staticdefaults = (
1166: coursequota => 20,
1167: uploadquota => 500,
1168: );
1169: my %default;
1170: $default{'coursequota'} = $staticdefaults{'coursequota'};
1171: my %domdefs = &Apache::lonnet::get_domain_defaults($cdom);
1172: $default{'uploadquota'} = $domdefs{'uploadquota'};
1173: if ($default{'uploadquota'} eq '') {
1174: $default{'uploadquota'} = $staticdefaults{'uploadquota'};
1175: }
1176: my (%cenv,%showresult);
1177: foreach my $item ('coursequota','uploadquota') {
1178: if ($env{'form.'.$item} ne '') {
1179: my $newquota = $env{'form.'.$item};
1180: if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
1181: $newquota = $1;
1182: if ($oldsettings{'internal.'.$item} == $newquota) {
1183: if ($item eq 'coursequota') {
1184: $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] MB.',$newquota).'<br />');
1185: } else {
1186: $r->print(&mt('The disk space allocated for files uploaded via the Content Editor remains unchanged as [_1] MB.',$newquota).'<br />');
1187: }
1188: } else {
1189: $cenv{'internal.'.$item} = $newquota;
1190: $showresult{$item} = 1;
1191: }
1.28 raeburn 1192: } else {
1.61 raeburn 1193: if ($item eq 'coursequota') {
1194: $r->print(&mt('The proposed group portfolio quota contained invalid characters, so the quota is unchanged.').'<br />');
1195: } else {
1196: $r->print(&mt('The proposed quota for content uploaded via the Content Editor contained invalid characters, so the quota is unchanged.').'<br />');
1197:
1198: }
1199: }
1200: }
1201: }
1202: if (keys(%cenv)) {
1203: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
1204: $cnum);
1205: foreach my $key (sort(keys(%showresult))) {
1206: if (($oldsettings{'internal.'.$key} eq '') &&
1207: ($env{'form.'.$key} == $default{$key})) {
1208: if ($key eq 'uploadquota') {
1209: if ($type eq 'Community') {
1210: $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.',
1211: $default{$key}).'<br />');
1212: } else {
1213: $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.',
1214: $default{$key}).'<br />');
1215: }
1216: } else {
1.48 raeburn 1217: if ($type eq 'Community') {
1.61 raeburn 1218: $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] MB.',
1219: $default{$key}).'<br />');
1.48 raeburn 1220: } else {
1.61 raeburn 1221: $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] MB.',
1222: $default{$key}).'<br />');
1.48 raeburn 1223: }
1.61 raeburn 1224: }
1225: delete($showresult{$key});
1226: }
1227: }
1228: if ($putreply eq 'ok') {
1229: my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota','internal.uploadquota'],$cdom,$cnum);
1230: if ($showresult{'coursequota'}) {
1231: $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] MB.',
1232: '<b>'.$updatedsettings{'internal.coursequota'}.'</b>').'<br />');
1233: my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
1234: if ($usage >= $updatedsettings{'internal.coursequota'}) {
1235: my $newoverquota;
1236: if ($usage < $oldsettings{'internal.coursequota'}) {
1237: $newoverquota = 'now';
1238: }
1239: $r->print('<p>');
1240: if ($type eq 'Community') {
1241: $r->print(&mt('Disk usage [_1] exceeds the quota for this community.',$newoverquota).' '.
1242: &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 1243: } else {
1.61 raeburn 1244: $r->print(&mt('Disk usage [_1] exceeds the quota for this course.',$newoverquota).' '.
1245: &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 1246: }
1.61 raeburn 1247: $r->print('</p>');
1.28 raeburn 1248: }
1249: }
1.61 raeburn 1250: if ($showresult{'uploadquota'}) {
1251: $r->print(&mt('The disk space allocated for content uploaded directly via the Content Editor is now: [_1] MB.',
1252: '<b>'.$updatedsettings{'internal.uploadquota'}.'</b>').'<br />');
1253: }
1.28 raeburn 1254: } else {
1.63 raeburn 1255: $r->print(&mt('An error occurred storing the quota(s) for group portfolio files and/or uploaded content: ').
1.61 raeburn 1256: $putreply);
1.28 raeburn 1257: }
1258: }
1.48 raeburn 1259: $r->print('<p>'.
1260: '<a href="javascript:changePage(document.processquota,'."'menu'".')">'.
1261: &mt('Pick another action').'</a>');
1.28 raeburn 1262: $r->print(&hidden_form_elements().'</form>');
1263: return;
1.1 raeburn 1264: }
1265:
1.57 raeburn 1266: sub modify_anonsurvey_threshold {
1267: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1268: &print_header($r,$type);
1269: $r->print('<form action="/adm/modifycourse" method="post" name="processthreshold">'."\n".
1270: '<h3>'.&mt('Responder threshold required for display of anonymous survey submissions:').
1271: ' <span class="LC_nobreak">'.$cdesc.'</span></h3><br />');
1272: my %oldsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
1273: my %domconfig =
1274: &Apache::lonnet::get_dom('configuration',['coursedefaults'],$cdom);
1275: my $defaultthreshold;
1276: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
1277: $defaultthreshold = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
1278: if ($defaultthreshold eq '') {
1279: $defaultthreshold = 10;
1280: }
1281: } else {
1282: $defaultthreshold = 10;
1283: }
1284: if ($env{'form.threshold'} eq '') {
1285: $r->print(&mt('The proposed responder threshold for display of anonymous survey submissions was blank, so the threshold is unchanged.'));
1286: } else {
1287: my $newthreshold = $env{'form.threshold'};
1288: if ($newthreshold =~ /^\s*(\d+)\s*$/) {
1289: $newthreshold = $1;
1290: if ($oldsettings{'internal.anonsurvey_threshold'} eq $env{'form.threshold'}) {
1291: $r->print(&mt('Responder threshold for anonymous survey submissions display remains unchanged: [_1].',$env{'form.threshold'}));
1292: } else {
1293: my %cenv = (
1294: 'internal.anonsurvey_threshold' => $env{'form.threshold'},
1295: );
1296: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
1297: $cnum);
1298: if (($oldsettings{'internal.anonsurvey_threshold'} eq '') &&
1299: ($env{'form.threshold'} == $defaultthreshold)) {
1300: $r->print(&mt('The responder threshold for display of anonymous survey submissions is the default for this domain: [_1].',$defaultthreshold));
1301: } else {
1302: if ($putreply eq 'ok') {
1303: my %updatedsettings = &Apache::lonnet::get('environment',['internal.anonsurvey_threshold'],$cdom,$cnum);
1304: $r->print(&mt('The responder threshold for display of anonymous survey submissions is now: [_1].','<b>'.$updatedsettings{'internal.anonsurvey_threshold'}.'</b>'));
1305: } else {
1306: $r->print(&mt('An error occurred storing the responder threshold for anonymous submissions display: ').
1307: $putreply);
1308: }
1309: }
1310: }
1311: } else {
1312: $r->print(&mt('The proposed responder threshold for display of anonymous submissions contained invalid characters, so the threshold is unchanged.'));
1313: }
1314: }
1315: $r->print('<p>'.
1316: '<a href="javascript:changePage(document.processthreshold,'."'menu'".')">'.
1317: &mt('Pick another action').'</a>');
1318: $r->print(&hidden_form_elements().'</form>');
1319: return;
1320: }
1321:
1.38 raeburn 1322: sub modify_catsettings {
1.48 raeburn 1323: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1324: &print_header($r,$type);
1325: my ($ccrole,%desc);
1326: if ($type eq 'Community') {
1327: $desc{'hidefromcat'} = &mt('Excluded from community catalog');
1328: $desc{'categories'} = &mt('Assigned categories for this community');
1329: $ccrole = 'co';
1330: } else {
1331: $desc{'hidefromcat'} = &mt('Excluded from course catalog');
1332: $desc{'categories'} = &mt('Assigned categories for this course');
1333: $ccrole = 'cc';
1334: }
1.38 raeburn 1335: $r->print('
1336: <form action="/adm/modifycourse" method="post" name="processcat">
1337: <h3>'.&mt('Category settings').'</h3>');
1338: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49 raeburn 1339: my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38 raeburn 1340: if (@cat_params > 0) {
1341: my (%cenv,@changes,@nochanges);
1342: my %currsettings =
1343: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
1344: my (@newcategories,%showitem);
1345: if (grep(/^togglecats$/,@cat_params)) {
1346: if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) {
1347: push(@changes,'hidefromcat');
1348: $cenv{'hidefromcat'} = $env{'form.hidefromcat'};
1349: } else {
1350: push(@nochanges,'hidefromcat');
1351: }
1352: if ($env{'form.hidefromcat'} eq 'yes') {
1353: $showitem{'hidefromcat'} = '"'.&mt('Yes')."'";
1354: } else {
1355: $showitem{'hidefromcat'} = '"'.&mt('No').'"';
1356: }
1357: }
1358: if (grep(/^categorize$/,@cat_params)) {
1359: my (@cats,@trails,%allitems,%idx,@jsarray);
1360: if (ref($domconf{'coursecategories'}) eq 'HASH') {
1361: my $cathash = $domconf{'coursecategories'}{'cats'};
1362: if (ref($cathash) eq 'HASH') {
1363: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
1364: \%allitems,\%idx,\@jsarray);
1365: }
1366: }
1367: @newcategories = &Apache::loncommon::get_env_multiple('form.usecategory');
1368: if (@newcategories == 0) {
1369: $showitem{'categories'} = '"'.&mt('None').'"';
1370: } else {
1371: $showitem{'categories'} = '<ul>';
1372: foreach my $item (@newcategories) {
1373: $showitem{'categories'} .= '<li>'.$trails[$allitems{$item}].'</li>';
1374: }
1375: $showitem{'categories'} .= '</ul>';
1376: }
1377: my $catchg = 0;
1378: if ($currsettings{'categories'} ne '') {
1379: my @currcategories = split('&',$currsettings{'categories'});
1380: foreach my $cat (@currcategories) {
1381: if (!grep(/^\Q$cat\E$/,@newcategories)) {
1382: $catchg = 1;
1383: last;
1384: }
1385: }
1386: if (!$catchg) {
1387: foreach my $cat (@newcategories) {
1388: if (!grep(/^\Q$cat\E$/,@currcategories)) {
1389: $catchg = 1;
1390: last;
1391: }
1392: }
1393: }
1394: } else {
1395: if (@newcategories > 0) {
1396: $catchg = 1;
1397: }
1398: }
1399: if ($catchg) {
1400: $cenv{'categories'} = join('&',@newcategories);
1401: push(@changes,'categories');
1402: } else {
1403: push(@nochanges,'categories');
1404: }
1405: if (@changes > 0) {
1406: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1407: if ($putreply eq 'ok') {
1408: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
1409: $cnum,undef,undef,'.');
1410: if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
1411: if (grep(/^hidefromcat$/,@changes)) {
1412: $crsinfo{$env{'form.pickedcourse'}}{'hidefromcat'} = $env{'form.hidefromcat'};
1413: }
1414: if (grep(/^categories$/,@changes)) {
1415: $crsinfo{$env{'form.pickedcourse'}}{'categories'} = $cenv{'categories'};
1416: }
1417: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1418: my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
1419: }
1.48 raeburn 1420: $r->print(&mt('The following changes occurred:').'<ul>');
1.38 raeburn 1421: foreach my $item (@changes) {
1.48 raeburn 1422: $r->print('<li>'.&mt('[_1] now set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38 raeburn 1423: }
1424: $r->print('</ul><br />');
1425: }
1426: }
1427: if (@nochanges > 0) {
1.48 raeburn 1428: $r->print(&mt('The following were unchanged:').'<ul>');
1.38 raeburn 1429: foreach my $item (@nochanges) {
1.48 raeburn 1430: $r->print('<li>'.&mt('[_1] still set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38 raeburn 1431: }
1432: $r->print('</ul>');
1433: }
1434: }
1435: } else {
1.48 raeburn 1436: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
1437: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
1438: '=1&destinationurl=/adm/courseprefs','&<>"');
1439: if ($type eq 'Community') {
1440: $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 />');
1441: } else {
1442: $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 />');
1443: }
1.38 raeburn 1444: }
1445: $r->print('<br />'."\n".
1446: '<a href="javascript:changePage(document.processcat,'."'menu'".')">'.
1.48 raeburn 1447: &mt('Pick another action').'</a>');
1.38 raeburn 1448: $r->print(&hidden_form_elements().'</form>');
1449: return;
1450: }
1451:
1.1 raeburn 1452: sub print_header {
1.48 raeburn 1453: my ($r,$type,$javascript_validations) = @_;
1.28 raeburn 1454: my $phase = "start";
1455: if ( exists($env{'form.phase'}) ) {
1456: $phase = $env{'form.phase'};
1457: }
1458: my $js = qq|
1.60 raeburn 1459:
1.28 raeburn 1460: function changePage(formname,newphase) {
1461: formname.phase.value = newphase;
1462: if (newphase == 'processparms') {
1463: return;
1.1 raeburn 1464: }
1.28 raeburn 1465: formname.submit();
1466: }
1.60 raeburn 1467:
1.28 raeburn 1468: |;
1469: if ($phase eq 'setparms') {
1.60 raeburn 1470: $js .= $javascript_validations;
1.28 raeburn 1471: } elsif ($phase eq 'courselist') {
1472: $js .= qq|
1.60 raeburn 1473:
1.28 raeburn 1474: function gochoose(cname,cdom,cdesc) {
1475: document.courselist.pickedcourse.value = cdom+'_'+cname;
1476: document.courselist.submit();
1477: }
1.60 raeburn 1478:
1479: function hide_searching() {
1480: if (document.getElementById('searching')) {
1481: document.getElementById('searching').style.display = 'none';
1482: }
1483: return;
1484: }
1485:
1.28 raeburn 1486: |;
1487: } elsif ($phase eq 'setquota') {
1.57 raeburn 1488: my $invalid = &mt('The quota you entered contained invalid characters.');
1489: my $alert = &mt('You must enter a number');
1490: my $regexp = '/^\s*(\d+\.?\d*|\.\d+)\s*$/';
1491: $js .= <<"ENDSCRIPT";
1.60 raeburn 1492:
1.57 raeburn 1493: function verify_quota() {
1494: var newquota = document.setquota.coursequota.value;
1495: var num_reg = $regexp;
1.28 raeburn 1496: if (num_reg.test(newquota)) {
1.57 raeburn 1497: changePage(document.setquota,'processquota');
1.1 raeburn 1498: } else {
1.57 raeburn 1499: alert("$invalid\\n$alert");
1500: return false;
1.1 raeburn 1501: }
1.57 raeburn 1502: return true;
1503: }
1.60 raeburn 1504:
1.57 raeburn 1505: ENDSCRIPT
1506: } elsif ($phase eq 'setanon') {
1507: my $invalid = &mt('The responder threshold you entered is invalid.');
1508: my $alert = &mt('You must enter a positive integer.');
1509: my $regexp = ' /^\s*\d+\s*$/';
1510: $js .= <<"ENDSCRIPT";
1.60 raeburn 1511:
1.57 raeburn 1512: function verify_anon_threshold() {
1513: var newthreshold = document.setanon.threshold.value;
1514: var num_reg = $regexp;
1515: if (num_reg.test(newthreshold)) {
1516: if (newthreshold > 0) {
1517: changePage(document.setanon,'processthreshold');
1518: } else {
1519: alert("$invalid\\n$alert");
1520: return false;
1521: }
1522: } else {
1523: alert("$invalid\\n$alert");
1524: return false;
1525: }
1526: return true;
1.28 raeburn 1527: }
1.60 raeburn 1528:
1.28 raeburn 1529: ENDSCRIPT
1.1 raeburn 1530: }
1.60 raeburn 1531:
1.37 raeburn 1532: my $starthash;
1533: if ($env{'form.phase'} eq 'ccrole') {
1534: $starthash = {
1535: add_entries => {'onload' => "javascript:document.ccrole.submit();"},
1536: };
1.60 raeburn 1537: } elsif ($phase eq 'courselist') {
1538: $starthash = {
1539: add_entries => {'onload' => "hide_searching();"},
1540: };
1.37 raeburn 1541: }
1.48 raeburn 1542: $r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
1.60 raeburn 1543: &Apache::lonhtmlcommon::scripttag($js),
1544: $starthash));
1.48 raeburn 1545: my $bread_text = "View/Modify Courses/Communities";
1546: if ($type eq 'Community') {
1547: $bread_text = 'Community Settings';
1.41 raeburn 1548: } else {
1.48 raeburn 1549: $bread_text = 'Course Settings';
1.41 raeburn 1550: }
1.48 raeburn 1551: $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
1.5 raeburn 1552: return;
1.1 raeburn 1553: }
1554:
1555: sub print_footer {
1.23 albertel 1556: my ($r) = @_;
1557: $r->print('<br />'.&Apache::loncommon::end_page());
1.5 raeburn 1558: return;
1.3 raeburn 1559: }
1560:
1561: sub check_course {
1.28 raeburn 1562: my ($r,$dom,$domdesc) = @_;
1563: my ($ok_course,$description,$instcode,$owner);
1.35 raeburn 1564: my %args = (
1565: one_time => 1,
1566: );
1567: my %coursehash =
1568: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
1569: my $cnum = $coursehash{'num'};
1570: my $cdom = $coursehash{'domain'};
1571: if ($cdom eq $dom) {
1572: my $description;
1573: my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
1.38 raeburn 1574: $cnum,undef,undef,'.');
1.35 raeburn 1575: if (keys(%courseIDs) > 0) {
1576: $ok_course = 'ok';
1577: my ($instcode,$owner);
1578: if (ref($courseIDs{$cdom.'_'.$cnum}) eq 'HASH') {
1579: $description = $courseIDs{$cdom.'_'.$cnum}{'description'};
1580: $instcode = $courseIDs{$cdom.'_'.$cnum}{'inst_code'};
1581: $owner = $courseIDs{$cdom.'_'.$cnum}{'owner'};
1582: } else {
1583: ($description,$instcode,$owner) =
1584: split(/:/,$courseIDs{$cdom.'_'.$cnum});
1585: }
1586: $description = &unescape($description);
1587: $instcode = &unescape($instcode);
1588: if ($instcode) {
1589: $description .= " ($instcode)";
1.5 raeburn 1590: }
1.35 raeburn 1591: return ($ok_course,$description);
1.3 raeburn 1592: }
1593: }
1.1 raeburn 1594: }
1595:
1.28 raeburn 1596: sub course_settings_descrip {
1.48 raeburn 1597: my ($type) = @_;
1598: my %longtype;
1599: if ($type eq 'Community') {
1600: %longtype = &Apache::lonlocal::texthash(
1601: 'courseowner' => "Username:domain of community owner",
1.50 raeburn 1602: 'co-owners' => "Username:domain of each co-owner",
1.48 raeburn 1603: );
1604: } else {
1605: %longtype = &Apache::lonlocal::texthash(
1.28 raeburn 1606: 'authtype' => 'Default authentication method',
1607: 'autharg' => 'Default authentication parameter',
1608: 'autoadds' => 'Automated adds',
1609: 'autodrops' => 'Automated drops',
1610: 'autostart' => 'Date of first automated enrollment',
1611: 'autoend' => 'Date of last automated enrollment',
1612: 'default_enrollment_start_date' => 'Date of first student access',
1613: 'default_enrollment_end_date' => 'Date of last student access',
1614: 'coursecode' => 'Official course code',
1615: 'courseowner' => "Username:domain of course owner",
1.50 raeburn 1616: 'co-owners' => "Username:domain of each co-owner",
1.28 raeburn 1617: 'notifylist' => 'Course Coordinators to be notified of enrollment changes',
1.48 raeburn 1618: 'sectionnums' => 'Course section number:LON-CAPA section',
1619: 'crosslistings' => 'Crosslisted class:LON-CAPA section',
1.60 raeburn 1620: 'defaultcredits' => 'Credits',
1.48 raeburn 1621: );
1622: }
1.28 raeburn 1623: return %longtype;
1624: }
1625:
1626: sub hidden_form_elements {
1627: my $hidden_elements =
1.46 raeburn 1628: &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
1.37 raeburn 1629: 'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
1.57 raeburn 1630: 'locarg','krbarg','krbver','counter','hidefromcat','usecategory',
1.61 raeburn 1631: 'threshold','defaultcredits','uploadquota'])."\n".
1.37 raeburn 1632: '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
1.28 raeburn 1633: return $hidden_elements;
1634: }
1.1 raeburn 1635:
1.60 raeburn 1636: sub showcredits {
1637: my ($dom) = @_;
1638: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1639: if ($domdefaults{'officialcredits'} || $domdefaults{'unofficialcredits'}) {
1640: return 1;
1641: }
1642: }
1643:
1.1 raeburn 1644: sub handler {
1645: my $r = shift;
1646: if ($r->header_only) {
1647: &Apache::loncommon::content_type($r,'text/html');
1648: $r->send_http_header;
1649: return OK;
1650: }
1.28 raeburn 1651: my $dom = $env{'request.role.domain'};
1.31 albertel 1652: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.28 raeburn 1653: if (&Apache::lonnet::allowed('ccc',$dom)) {
1.1 raeburn 1654: &Apache::loncommon::content_type($r,'text/html');
1655: $r->send_http_header;
1656:
1.28 raeburn 1657: &Apache::lonhtmlcommon::clear_breadcrumbs();
1658:
1659: my $phase = $env{'form.phase'};
1.46 raeburn 1660: if ($env{'form.updater'}) {
1661: $phase = '';
1662: }
1.37 raeburn 1663: if ($phase eq '') {
1664: &Apache::lonhtmlcommon::add_breadcrumb
1.28 raeburn 1665: ({href=>"/adm/modifycourse",
1.48 raeburn 1666: text=>"Course/Community search"});
1.28 raeburn 1667: &print_course_search_page($r,$dom,$domdesc);
1.1 raeburn 1668: } else {
1.37 raeburn 1669: my $firstform = $phase;
1670: if ($phase eq 'courselist') {
1671: $firstform = 'filterpicker';
1.48 raeburn 1672: }
1673: my $choose_text;
1674: my $type = $env{'form.type'};
1675: if ($type eq '') {
1676: $type = 'Course';
1677: }
1678: if ($type eq 'Community') {
1679: $choose_text = "Choose a community";
1680: } else {
1681: $choose_text = "Choose a course";
1.37 raeburn 1682: }
1.28 raeburn 1683: &Apache::lonhtmlcommon::add_breadcrumb
1.37 raeburn 1684: ({href=>"javascript:changePage(document.$firstform,'')",
1.48 raeburn 1685: text=>"Course/Community search"},
1.37 raeburn 1686: {href=>"javascript:changePage(document.$phase,'courselist')",
1.48 raeburn 1687: text=>$choose_text});
1.28 raeburn 1688: if ($phase eq 'courselist') {
1689: &print_course_selection_page($r,$dom,$domdesc);
1690: } else {
1691: my ($checked,$cdesc) = &check_course($r,$dom,$domdesc);
1692: if ($checked eq 'ok') {
1.48 raeburn 1693: my $enter_text;
1694: if ($type eq 'Community') {
1695: $enter_text = 'Enter community';
1696: } else {
1697: $enter_text = 'Enter course';
1698: }
1.28 raeburn 1699: if ($phase eq 'menu') {
1.37 raeburn 1700: &Apache::lonhtmlcommon::add_breadcrumb
1701: ({href=>"javascript:changePage(document.$phase,'menu')",
1702: text=>"Pick action"});
1.48 raeburn 1703: &print_modification_menu($r,$cdesc,$domdesc,$dom,$type);
1.37 raeburn 1704: } elsif ($phase eq 'ccrole') {
1705: &Apache::lonhtmlcommon::add_breadcrumb
1706: ({href=>"javascript:changePage(document.$phase,'ccrole')",
1.48 raeburn 1707: text=>$enter_text});
1708: &print_ccrole_selected($r,$type);
1.28 raeburn 1709: } else {
1.37 raeburn 1710: &Apache::lonhtmlcommon::add_breadcrumb
1711: ({href=>"javascript:changePage(document.$phase,'menu')",
1712: text=>"Pick action"});
1.28 raeburn 1713: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
1714: if ($phase eq 'setquota') {
1715: &Apache::lonhtmlcommon::add_breadcrumb
1716: ({href=>"javascript:changePage(document.$phase,'$phase')",
1717: text=>"Set quota"});
1.38 raeburn 1718: &print_setquota($r,$cdom,$cnum,$cdesc,$type);
1.28 raeburn 1719: } elsif ($phase eq 'processquota') {
1720: &Apache::lonhtmlcommon::add_breadcrumb
1721: ({href=>"javascript:changePage(document.$phase,'setquota')",
1722: text=>"Set quota"});
1723: &Apache::lonhtmlcommon::add_breadcrumb
1724: ({href=>"javascript:changePage(document.$phase,'$phase')",
1725: text=>"Result"});
1.48 raeburn 1726: &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.57 raeburn 1727: } elsif ($phase eq 'setanon') {
1728: &Apache::lonhtmlcommon::add_breadcrumb
1729: ({href=>"javascript:changePage(document.$phase,'$phase')",
1730: text=>"Threshold for anonymous submissions display"});
1731: &print_set_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$type);
1732:
1733: } elsif ($phase eq 'processthreshold') {
1734: &Apache::lonhtmlcommon::add_breadcrumb
1735: ({href=>"javascript:changePage(document.$phase,'setanon')",
1736: text=>"Threshold for anonymous submissions display"});
1737: &Apache::lonhtmlcommon::add_breadcrumb
1738: ({href=>"javascript:changePage(document.$phase,'$phase')",
1739: text=>"Result"});
1740: &modify_anonsurvey_threshold($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1741: } elsif ($phase eq 'viewparms') {
1.28 raeburn 1742: &Apache::lonhtmlcommon::add_breadcrumb
1743: ({href=>"javascript:changePage(document.$phase,'viewparms')",
1744: text=>"Display settings"});
1745: &print_settings_display($r,$cdom,$cnum,$cdesc,$type);
1746: } elsif ($phase eq 'setparms') {
1747: &Apache::lonhtmlcommon::add_breadcrumb
1748: ({href=>"javascript:changePage(document.$phase,'$phase')",
1749: text=>"Change settings"});
1.48 raeburn 1750: &print_course_modification_page($r,$cdom,$cnum,$cdesc,$type);
1.28 raeburn 1751: } elsif ($phase eq 'processparms') {
1752: &Apache::lonhtmlcommon::add_breadcrumb
1753: ({href=>"javascript:changePage(document.$phase,'setparms')",
1754: text=>"Change settings"});
1755: &Apache::lonhtmlcommon::add_breadcrumb
1756: ({href=>"javascript:changePage(document.$phase,'$phase')",
1757: text=>"Result"});
1.30 raeburn 1758: &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.38 raeburn 1759: } elsif ($phase eq 'catsettings') {
1760: &Apache::lonhtmlcommon::add_breadcrumb
1761: ({href=>"javascript:changePage(document.$phase,'$phase')",
1762: text=>"Catalog settings"});
1763: &print_catsettings($r,$cdom,$cnum,$cdesc,$type);
1764: } elsif ($phase eq 'processcat') {
1765: &Apache::lonhtmlcommon::add_breadcrumb
1766: ({href=>"javascript:changePage(document.$phase,'catsettings')",
1767: text=>"Catalog settings"});
1768: &Apache::lonhtmlcommon::add_breadcrumb
1769: ({href=>"javascript:changePage(document.$phase,'$phase')",
1770: text=>"Result"});
1.48 raeburn 1771: &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.28 raeburn 1772: }
1773: }
1774: } else {
1.48 raeburn 1775: $r->print('<span class="LC_error">');
1776: if ($type eq 'Community') {
1777: $r->print(&mt('The course you selected is not a valid course in this domain'));
1778: } else {
1779: $r->print(&mt('The community you selected is not a valid community in this domain'));
1780: }
1781: $r->print(" ($domdesc)</span>");
1.28 raeburn 1782: }
1783: }
1.1 raeburn 1784: }
1.28 raeburn 1785: &print_footer($r);
1.1 raeburn 1786: } else {
1.16 albertel 1787: $env{'user.error.msg'}=
1.48 raeburn 1788: "/adm/modifycourse:ccc:0:0:Cannot modify course/community settings";
1.1 raeburn 1789: return HTTP_NOT_ACCEPTABLE;
1790: }
1791: return OK;
1792: }
1793:
1794: 1;
1795: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>