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