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