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