Annotation of loncom/interface/lonmodifycourse.pm, revision 1.49
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.49 ! raeburn 4: # $Id: lonmodifycourse.pm,v 1.48 2009/11/09 03:50:27 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.48 raeburn 42: my ($type) = @_;
43: if ($type eq 'Community') {
44: return ('courseowner');
45: } else {
46: return ('courseowner','coursecode','authtype','autharg');
47: }
48: }
49:
50: sub autoenroll_keys {
51: my $internals = ['coursecode','courseowner','authtype','autharg','autoadds','autodrops',
52: 'autostart','autoend','sectionnums','crosslistings'];
53: my $accessdates = ['default_enrollment_start_date','default_enrollment_end_date'];
54: return ($internals,$accessdates);
1.28 raeburn 55: }
56:
1.38 raeburn 57: sub catalog_settable {
1.49 ! raeburn 58: my ($confhash,$type) = @_;
1.38 raeburn 59: my @settable;
60: if (ref($confhash) eq 'HASH') {
1.49 ! raeburn 61: if ($type eq 'Community') {
! 62: if ($confhash->{'togglecatscomm'} ne 'comm') {
! 63: push(@settable,'togglecats');
! 64: }
! 65: if ($confhash->{'categorizecomm'} ne 'comm') {
! 66: push(@settable,'categorize');
! 67: }
! 68: } else {
! 69: if ($confhash->{'togglecats'} ne 'crs') {
! 70: push(@settable,'togglecats');
! 71: }
! 72: if ($confhash->{'categorize'} ne 'crs') {
! 73: push(@settable,'categorize');
! 74: }
1.38 raeburn 75: }
76: } else {
77: push(@settable,('togglecats','categorize'));
78: }
79: return @settable;
80: }
81:
1.28 raeburn 82: sub get_enrollment_settings {
83: my ($cdom,$cnum) = @_;
1.48 raeburn 84: my ($internals,$accessdates) = &autoenroll_keys();
85: my @items;
86: if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
87: @items = map { 'internal.'.$_; } (@{$internals});
88: push(@items,@{$accessdates});
89: }
90: my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
1.28 raeburn 91: my %enrollvar;
92: $enrollvar{'autharg'} = '';
93: $enrollvar{'authtype'} = '';
1.48 raeburn 94: foreach my $item (keys(%settings)) {
1.28 raeburn 95: if ($item =~ m/^internal\.(.+)$/) {
96: my $type = $1;
97: if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
98: if ($settings{$item} == 1) {
99: $enrollvar{$type} = "ON";
100: } else {
101: $enrollvar{$type} = "OFF";
1.10 raeburn 102: }
1.28 raeburn 103: } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
104: if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
1.48 raeburn 105: $enrollvar{$type} = &mt('No end date');
1.28 raeburn 106: } else {
1.48 raeburn 107: $enrollvar{$type} = &Apache::lonlocal::locallocaltime($settings{$item});
1.14 raeburn 108: }
1.30 raeburn 109: } elsif ($type eq "sectionnums") {
1.28 raeburn 110: $enrollvar{$type} = $settings{$item};
111: $enrollvar{$type} =~ s/,/, /g;
112: } elsif ($type eq "authtype"
113: || $type eq "autharg" || $type eq "coursecode"
114: || $type eq "crosslistings") {
115: $enrollvar{$type} = $settings{$item};
116: } elsif ($type eq 'courseowner') {
117: if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
118: $enrollvar{$type} = $settings{$item};
119: } else {
120: if ($settings{$item} ne '') {
121: $enrollvar{$type} = $settings{$item}.':'.$cdom;
1.26 raeburn 122: }
1.1 raeburn 123: }
1.28 raeburn 124: }
125: } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
126: my $type = $1;
127: if ( ($type eq 'end') && ($settings{$item} == 0) ) {
1.48 raeburn 128: $enrollvar{$item} = &mt('No end date');
1.28 raeburn 129: } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
130: $enrollvar{$item} = 'When enrolled';
131: } else {
1.48 raeburn 132: $enrollvar{$item} = &Apache::lonlocal::locallocaltime($settings{$item});
1.1 raeburn 133: }
134: }
135: }
1.28 raeburn 136: return %enrollvar;
137: }
138:
139: sub print_course_search_page {
140: my ($r,$dom,$domdesc) = @_;
1.48 raeburn 141: my $action = '/adm/modifycourse';
142: my $type = $env{'form.type'};
143: if (!defined($env{'form.type'})) {
144: $type = 'Course';
145: }
146: &print_header($r,$type);
1.28 raeburn 147: my $filterlist = ['descriptfilter',
148: 'instcodefilter','ownerfilter',
1.44 raeburn 149: 'coursefilter'];
1.28 raeburn 150: my $filter = {};
1.48 raeburn 151: my ($numtitles,$cctitle,$dctitle);
152: my $ccrole = 'cc';
153: if ($type eq 'Community') {
154: $ccrole = 'co';
1.46 raeburn 155: }
1.48 raeburn 156: $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.46 raeburn 157: $dctitle = &Apache::lonnet::plaintext('dc');
158: $r->print(&Apache::lonpickcourse::js_changer());
1.48 raeburn 159: if ($type eq 'Community') {
160: $r->print('<h3>'.&mt('Search for a community in the [_1] domain',$domdesc).'</h3>');
161: } else {
162: $r->print('<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>');
1.46 raeburn 163: }
1.28 raeburn 164: $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
1.44 raeburn 165: undef,undef,$filter,$action,\$numtitles,'modifycourse'));
1.48 raeburn 166: if ($type eq 'Community') {
167: $r->print(&mt('Actions available after searching for a community:').'<ul>'.
168: '<li>'.&mt('Enter the community with the role of [_1]',$cctitle).'</li>'."\n".
169: '<li>'.&mt('View or modify community settings which only a [_1] may modify.',$dctitle).
170: '</li>'."\n".'</ul>');
171: } else {
172: $r->print(&mt('Actions available after searching for a course:').'<ul>'.
173: '<li>'.&mt('Enter the course with the role of [_1]',$cctitle).'</li>'."\n".
174: '<li>'.&mt('View or modify course settings which only a [_1] may modify.',$dctitle).
175: '</li>'."\n".'</ul>');
176: }
1.28 raeburn 177: }
178:
179: sub print_course_selection_page {
180: my ($r,$dom,$domdesc) = @_;
1.48 raeburn 181: my $type = $env{'form.type'};
182: if (!defined($type)) {
183: $type = 'Course';
184: }
185: &print_header($r,$type);
1.28 raeburn 186:
187: # Criteria for course search
188: my $filterlist = ['descriptfilter',
189: 'instcodefilter','ownerfilter',
190: 'ownerdomfilter','coursefilter'];
191: my %filter;
192: my $action = '/adm/modifycourse';
193: my $dctitle = &Apache::lonnet::plaintext('dc');
1.46 raeburn 194: my $numtitles;
195: $r->print(&Apache::lonpickcourse::js_changer());
1.48 raeburn 196: $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br />');
1.28 raeburn 197: $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
1.46 raeburn 198: undef,undef,\%filter,$action,\$numtitles));
1.28 raeburn 199: $filter{'domainfilter'} = $dom;
200: my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,
1.46 raeburn 201: \%filter,$numtitles);
202: &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,undef,undef,
1.28 raeburn 203: %courses);
1.1 raeburn 204: return;
205: }
206:
1.28 raeburn 207: sub print_modification_menu {
1.48 raeburn 208: my ($r,$cdesc,$domdesc,$dom,$type) = @_;
209: &print_header($r,$type);
210: my ($ccrole,$setquota_text,$setparams_text,$cat_text);
211: if ($type eq 'Community') {
212: $ccrole = 'co';
213: } else {
214: $ccrole = 'cc';
215: }
1.37 raeburn 216: my $action = '/adm/modifycourse';
1.48 raeburn 217: if ($type eq 'Community') {
218: $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a community.');
219: $setparams_text = 'View/Modify community owner';
220: $cat_text = 'View/Modify catalog settings for community';
221: } else {
222: $setquota_text = &mt('Total disk space allocated for storage of portfolio files in all groups in a course.');
223: $setparams_text = 'View/Modify course owner, institutional code, and default authentication';
224: $cat_text = 'View/Modify catalog settings for course';
225: }
1.28 raeburn 226: my @menu =
227: (
1.48 raeburn 228: { text => $setparams_text,
229: phase => 'setparms',
230: },
231: { text => 'View/Modify quota for group portfolio files',
1.28 raeburn 232: phase => 'setquota',
1.48 raeburn 233: }
234: );
1.38 raeburn 235: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
1.49 ! raeburn 236: my @additional_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38 raeburn 237: if (@additional_params > 0) {
1.48 raeburn 238: push (@menu, { text => $cat_text,
1.38 raeburn 239: phase => 'catsettings',
240: });
241: }
1.48 raeburn 242: unless ($type eq 'Community') {
243: push(@menu,
244: { text => 'Display current settings for automated enrollment',
245: phase => 'viewparms',
246: }
247: );
248: }
249: my $menu_html = '<h3>'.&mt('View/Modify settings for: ').
250: ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n";
251: if ($type eq 'Community') {
252: $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:');
253: } else {
254: $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:');
255: }
256: $menu_html .= '<ul>';
257: if ($type eq 'Community') {
258: $menu_html .= '<li>'.&mt('Community owner (permitted to assign Coordinator roles in the community).').'</li>';
259: } else {
260: $menu_html .= '<li>'.&mt('Course owner (permitted to assign Course Coordinator roles in the course).').'</li>'.
261: '<li>'.&mt("Institutional code and default authentication (both required for auto-enrollment of students from institutional datafeeds).").'</li>';
262: }
263: $menu_html .= '<li>'.$setquota_text.'</li>'."\n";
1.38 raeburn 264: foreach my $item (@additional_params) {
1.48 raeburn 265: if ($type eq 'Community') {
266: if ($item eq 'togglecats') {
267: $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";
268: } elsif ($item eq 'categorize') {
269: $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";
270: }
271: } else {
272: if ($item eq 'togglecats') {
273: $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";
274: } elsif ($item eq 'categorize') {
275: $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";
276: }
1.38 raeburn 277: }
278: }
279: $menu_html .= ' </ul>
1.37 raeburn 280: <form name="menu" method="post" action="'.$action.'" />'."\n".
281: &hidden_form_elements();
1.28 raeburn 282: foreach my $menu_item (@menu) {
1.48 raeburn 283: $menu_html.='<h3>';
1.28 raeburn 284: $menu_html.=
285: qq|<a href="javascript:changePage(document.menu,'$menu_item->{'phase'}')">|;
1.48 raeburn 286: $menu_html.= &mt($menu_item->{'text'}).'</a>';
287: $menu_html.='</h3>';
1.3 raeburn 288: }
1.28 raeburn 289:
290: $r->print($menu_html);
291: return;
292: }
293:
1.37 raeburn 294: sub print_ccrole_selected {
1.48 raeburn 295: my ($r,$type) = @_;
296: &print_header($r,$type);
1.37 raeburn 297: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
298: $r->print('<form name="ccrole" method="post" action="/adm/roles">
299: <input type="hidden" name="selectrole" value="1" />
300: <input type="hidden" name="newrole" value="cc./'.$cdom.'/'.$cnum.'" />
301: </form>');
302: }
303:
1.28 raeburn 304: sub print_settings_display {
305: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
306: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.48 raeburn 307: my %longtype = &course_settings_descrip($type);
1.28 raeburn 308: my %lt = &Apache::lonlocal::texthash(
1.48 raeburn 309: 'valu' => 'Current value',
310: 'cour' => 'Current settings are:',
311: 'cose' => "Settings which control auto-enrollment using classlists from your institution's student information system fall into two groups:",
312: 'dcon' => 'Modifiable only by Domain Coordinator',
313: 'back' => 'Pick another action',
1.28 raeburn 314: );
1.48 raeburn 315: my $ccrole = 'cc';
316: if ($type eq 'Community') {
317: $ccrole = 'co';
318: }
319: my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.28 raeburn 320: my $dctitle = &Apache::lonnet::plaintext('dc');
1.48 raeburn 321: my @modifiable_params = &get_dc_settable($type);
322: my ($internals,$accessdates) = &autoenroll_keys();
323: my @items;
324: if ((ref($internals) eq 'ARRAY') && (ref($accessdates) eq 'ARRAY')) {
325: @items = (@{$internals},@{$accessdates});
326: }
1.28 raeburn 327: my $disp_table = &Apache::loncommon::start_data_table()."\n".
328: &Apache::loncommon::start_data_table_header_row()."\n".
1.48 raeburn 329: "<th> </th>\n".
1.28 raeburn 330: "<th>$lt{'valu'}</th>\n".
331: "<th>$lt{'dcon'}</th>\n".
332: &Apache::loncommon::end_data_table_header_row()."\n";
1.48 raeburn 333: foreach my $item (@items) {
1.28 raeburn 334: $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
1.48 raeburn 335: "<td><b>$longtype{$item}</b></td>\n".
336: "<td>$enrollvar{$item}</td>\n";
337: if (grep(/^\Q$item\E$/,@modifiable_params)) {
338: $disp_table .= '<td align="right">'.&mt('Yes').'</td>'."\n";
1.28 raeburn 339: } else {
1.48 raeburn 340: $disp_table .= '<td align="right">'.&mt('No').'</td>'."\n";
1.28 raeburn 341: }
342: $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
1.3 raeburn 343: }
1.28 raeburn 344: $disp_table .= &Apache::loncommon::end_data_table()."\n";
1.48 raeburn 345: &print_header($r,$type);
346: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
347: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
348: '=1&destinationurl=/adm/populate','&<>"');
349: $r->print('<h3>'.&mt('Current automated enrollment settings for:').
350: ' <span class="LC_nobreak">'.$cdesc.'</span></h3>'.
351: '<form action="/adm/modifycourse" method="post" name="viewparms">'."\n".
352: '<p>'.$lt{'cose'}.'<ul>'.
353: '<li>'.&mt('Settings modifiable by a [_1] via the [_2]Automated Enrollment Manager[_3] in a course.',$cctitle,'<a href="'.$escuri.'">','</a>').'</li>'.
354: '<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".
355: '</li></ul></p>'.
356: '<p>'.$lt{'cour'}.'</p><p>'.$disp_table.'</p><p>'.
357: '<a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>'."\n".
358: &hidden_form_elements().
359: '</p></form>'
360: );
1.28 raeburn 361: }
1.3 raeburn 362:
1.28 raeburn 363: sub print_setquota {
364: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
365: my %lt = &Apache::lonlocal::texthash(
1.48 raeburn 366: 'cquo' => 'Disk space for storage of group portfolio files for:',
1.28 raeburn 367: 'gpqu' => 'Course portfolio files disk space',
1.42 schafran 368: 'modi' => 'Save',
1.48 raeburn 369: 'back' => 'Pick another action',
1.28 raeburn 370: );
1.48 raeburn 371: if ($type eq 'Community') {
372: $lt{'gpqu'} = &mt('Community portfolio files disk space');
373: }
1.28 raeburn 374: my %settings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
375: my $coursequota = $settings{'internal.coursequota'};
376: if ($coursequota eq '') {
377: $coursequota = 20;
1.3 raeburn 378: }
1.48 raeburn 379: &print_header($r,$type);
1.28 raeburn 380: my $hidden_elements = &hidden_form_elements();
1.48 raeburn 381: my $helpitem = &Apache::loncommon::help_open_topic('Modify_Course_Quota');
1.28 raeburn 382: $r->print(<<ENDDOCUMENT);
383: <form action="/adm/modifycourse" method="post" name="setquota">
1.48 raeburn 384: <h3>$lt{'cquo'} <span class="LC_nobreak">$cdesc</span></h3>
1.28 raeburn 385: <p>
1.48 raeburn 386: $helpitem $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" /> Mb
1.28 raeburn 387: <input type="button" onClick="javascript:verify_quota(this.form)" value="$lt{'modi'}" />
388: </p>
389: $hidden_elements
390: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
391: </form>
392: ENDDOCUMENT
393: return;
394: }
1.3 raeburn 395:
1.38 raeburn 396: sub print_catsettings {
1.48 raeburn 397: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
398: &print_header($r,$type);
1.38 raeburn 399: my %lt = &Apache::lonlocal::texthash(
1.48 raeburn 400: 'back' => 'Pick another action',
401: 'catset' => 'Catalog Settings for Course',
402: 'visi' => 'Visibility in Course/Community Catalog',
403: 'exclude' => 'Exclude from course catalog:',
404: 'categ' => 'Categorize Course',
405: 'assi' => 'Assign one or more categories and/or subcategories to this course.'
1.38 raeburn 406: );
1.48 raeburn 407: if ($type eq 'Community') {
408: $lt{'catset'} = &mt('Catalog Settings for Community');
409: $lt{'exclude'} = &mt('Exclude from course catalog');
410: $lt{'categ'} = &mt('Categorize Community');
1.49 ! raeburn 411: $lt{'assi'} = &mt('Assign one or more subcategories to this community.');
1.48 raeburn 412: }
1.38 raeburn 413: $r->print('<form action="/adm/modifycourse" method="post" name="catsettings">'.
1.48 raeburn 414: '<h3>'.$lt{'catset'}.' <span class="LC_nobreak">'.$cdesc.'</span></h3>');
1.38 raeburn 415: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49 ! raeburn 416: my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38 raeburn 417: if (@cat_params > 0) {
418: my %currsettings =
419: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
420: if (grep(/^togglecats$/,@cat_params)) {
421: my $excludeon = '';
422: my $excludeoff = ' checked="checked" ';
423: if ($currsettings{'hidefromcat'} eq 'yes') {
424: $excludeon = $excludeoff;
425: $excludeoff = '';
426: }
1.48 raeburn 427: $r->print('<br /><h4>'.$lt{'visi'}.'</h4>'.
428: $lt{'exclude'}.
429: ' <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>');
430: if ($type eq 'Community') {
431: $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."));
432: } else {
433: $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>'.
434: '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code.').'</li>'.
435: '<li>'.&mt('The course has been categorized using at least one of the course categories defined for the domain.').'</li></ul>');
436: }
437: $r->print('</ul></p>');
1.38 raeburn 438: }
439: if (grep(/^categorize$/,@cat_params)) {
1.48 raeburn 440: $r->print('<br /><h4>'.$lt{'categ'}.'</h4>');
1.38 raeburn 441: if (ref($domconf{'coursecategories'}) eq 'HASH') {
442: my $cathash = $domconf{'coursecategories'}{'cats'};
443: if (ref($cathash) eq 'HASH') {
1.48 raeburn 444: $r->print($lt{'assi'}.'<br /><br />'.
1.38 raeburn 445: &Apache::loncommon::assign_categories_table($cathash,
1.49 ! raeburn 446: $currsettings{'categories'},$type));
1.38 raeburn 447: } else {
448: $r->print(&mt('No categories defined for this domain'));
449: }
450: } else {
451: $r->print(&mt('No categories defined for this domain'));
452: }
1.48 raeburn 453: unless ($type eq 'Community') {
454: $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>');
455: }
1.38 raeburn 456: }
1.48 raeburn 457: $r->print('<p><input type="button" name="chgcatsettings" value="'.
458: &mt('Save').'" onclick="javascript:changePage(document.catsettings,'."'processcat'".');" /></p>');
1.38 raeburn 459: } else {
1.48 raeburn 460: $r->print('<span class="LC_warning">');
461: if ($type eq 'Community') {
462: $r->print(&mt('Catalog settings in this domain are set in community context via "Community Configuration".'));
463: } else {
464: $r->print(&mt('Catalog settings in this domain are set in course context via "Course Configuration".'));
465: }
466: $r->print('</span><br /><br />'."\n".
1.38 raeburn 467: '<a href="javascript:changePage(document.catsettings,'."'menu'".');">'.
468: $lt{'back'}.'</a>');
469: }
470: $r->print(&hidden_form_elements().'</form>'."\n");
471: return;
472: }
473:
1.28 raeburn 474: sub print_course_modification_page {
1.48 raeburn 475: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
1.2 raeburn 476: my %lt=&Apache::lonlocal::texthash(
477: 'actv' => "Active",
478: 'inac' => "Inactive",
479: 'ownr' => "Owner",
480: 'name' => "Name",
1.26 raeburn 481: 'unme' => "Username:Domain",
1.2 raeburn 482: 'stus' => "Status",
1.48 raeburn 483: 'nocc' => 'There is currently no owner set for this course.',
1.32 raeburn 484: 'gobt' => "Save",
1.2 raeburn 485: );
1.48 raeburn 486: my ($ownertable,$ccrole,$javascript_validations,$authenitems,$ccname);
487: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
488: if ($type eq 'Community') {
489: $ccrole = 'co';
490: $lt{'nocc'} = &mt('There is currently no owner set for this community.');
491: } else {
492: $ccrole ='cc';
493: ($javascript_validations,$authenitems) = &gather_authenitems($cdom,\%enrollvar);
494: }
495: $ccname = &Apache::lonnet::plaintext($ccrole,$type);
496: my %roleshash = &Apache::lonnet::get_my_roles($cnum,$cdom,'','',[$ccrole]);
497: my (@local_ccs,%cc_status,%pname);
498: foreach my $item (keys(%roleshash)) {
499: my ($uname,$udom) = split(/:/,$item);
500: if (!grep(/^\Q$uname\E:\Q$udom\E$/,@local_ccs)) {
501: push(@local_ccs,$uname.':'.$udom);
502: $pname{$uname.':'.$udom} = &Apache::loncommon::plainname($uname,$udom);
503: $cc_status{$uname.':'.$udom} = $lt{'actv'};
1.1 raeburn 504: }
505: }
1.48 raeburn 506: if (($enrollvar{'courseowner'} ne '') &&
507: (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs))) {
508: push(@local_ccs,$enrollvar{'courseowner'});
1.26 raeburn 509: my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
510: $pname{$enrollvar{'courseowner'}} =
511: &Apache::loncommon::plainname($owneruname,$ownerdom);
1.48 raeburn 512: my $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
513: $cdom,$cnum,$ccrole);
1.19 raeburn 514: if ($active_cc eq 'active') {
1.2 raeburn 515: $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1 raeburn 516: } else {
1.2 raeburn 517: $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1 raeburn 518: }
519: }
1.48 raeburn 520: @local_ccs = sort(@local_ccs);
521: if (@local_ccs == 0) {
522: $ownertable = $lt{'nocc'};
523: } else {
524: my $numlocalcc = scalar(@local_ccs);
525: $ownertable = '<input type="hidden" name="numlocalcc" value="'.$numlocalcc.'" />'.
526: &Apache::loncommon::start_data_table()."\n".
527: &Apache::loncommon::start_data_table_header_row()."\n".
528: '<th>'.$lt{'ownr'}.'</th>'.
529: '<th>'.$lt{'name'}.'</th>'.
530: '<th>'.$lt{'unme'}.'</th>'.
531: '<th>'.$lt{'stus'}.'</th>'.
532: &Apache::loncommon::end_data_table_header_row()."\n";
533: foreach my $cc (@local_ccs) {
534: $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
535: if ($cc eq $enrollvar{'courseowner'}) {
536: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked" /></td>'."\n";
537: } else {
538: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" /></td>'."\n";
539: }
540: $ownertable .=
541: '<td>'.$pname{$cc}.'</td>'."\n".
542: '<td>'.$cc.'</td>'."\n".
543: '<td>'.$cc_status{$cc}.' '.$ccname.'</td>'."\n".
544: &Apache::loncommon::end_data_table_row()."\n";
545: }
546: $ownertable .= &Apache::loncommon::end_data_table();
547: }
548: &print_header($r,$type,$javascript_validations);
549: my $dctitle = &Apache::lonnet::plaintext('dc');
550: my $mainheader = &modifiable_only_title($type);
551: my $hidden_elements = &hidden_form_elements();
552: $r->print('<form action="/adm/modifycourse" method="post" name="'.$env{'form.phase'}.'">'."\n".
553: '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3><p>'.
554: &Apache::lonhtmlcommon::start_pick_box());
555: if ($type eq 'Community') {
556: $r->print(&Apache::lonhtmlcommon::row_title(
557: &Apache::loncommon::help_open_topic('Modify_Community_Owner').
558: ' '.&mt('Community Owner'))."\n");
559: } else {
560: $r->print(&Apache::lonhtmlcommon::row_title(
561: &Apache::loncommon::help_open_topic('Modify_Course_Instcode').
562: ' '.&mt('Course Code'))."\n".
563: '<input type="text" size="10" name="coursecode" value="'.$enrollvar{'coursecode'}.'" />'.
564: &Apache::lonhtmlcommon::row_closure().
565: &Apache::lonhtmlcommon::row_title(
566: &Apache::loncommon::help_open_topic('Modify_Course_Defaultauth').
567: ' '.&mt('Default Authentication method'))."\n".
568: $authenitems."\n".
569: &Apache::lonhtmlcommon::row_closure().
570: &Apache::lonhtmlcommon::row_title(
571: &Apache::loncommon::help_open_topic('Modify_Course_Owner').
572: ' '.&mt('Course Owner'))."\n");
573: }
574: $r->print($ownertable."\n".&Apache::lonhtmlcommon::row_closure(1).
575: &Apache::lonhtmlcommon::end_pick_box().'</p><p>'.$hidden_elements.
576: '<input type="button" onclick="javascript:changePage(this.form,'."'processparms'".');');
577: if ($type eq 'Community') {
578: $r->print('this.form.submit();"');
579: } else {
580: $r->print('javascript:verify_message(this.form);"');
581: }
582: $r->print('value="'.$lt{'gobt'}.'" /></p></form>');
583: return;
584: }
585:
586: sub modifiable_only_title {
587: my ($type) = @_;
588: my $dctitle = &Apache::lonnet::plaintext('dc');
589: if ($type eq 'Community') {
590: return &mt('Community settings modifiable only by [_1] for:',$dctitle);
591: } else {
592: return &mt('Course settings modifiable only by [_1] for:',$dctitle);
593: }
594: }
1.24 albertel 595:
1.48 raeburn 596: sub gather_authenitems {
597: my ($cdom,$enrollvar) = @_;
1.28 raeburn 598: my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
1.2 raeburn 599: my $curr_authtype = '';
600: my $curr_authfield = '';
1.48 raeburn 601: if (ref($enrollvar) eq 'HASH') {
602: if ($enrollvar->{'authtype'} =~ /^krb/) {
603: $curr_authtype = 'krb';
604: } elsif ($enrollvar->{'authtype'} eq 'internal' ) {
605: $curr_authtype = 'int';
606: } elsif ($enrollvar->{'authtype'} eq 'localauth' ) {
607: $curr_authtype = 'loc';
608: }
1.2 raeburn 609: }
610: unless ($curr_authtype eq '') {
611: $curr_authfield = $curr_authtype.'arg';
1.33 raeburn 612: }
1.48 raeburn 613: my $javascript_validations =
614: &Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,
615: $curr_authtype,$curr_authfield);
1.35 raeburn 616: my %param = ( formname => 'document.'.$env{'form.phase'},
1.48 raeburn 617: kerb_def_dom => $krbdefdom,
618: kerb_def_auth => $krbdef,
1.2 raeburn 619: mode => 'modifycourse',
620: curr_authtype => $curr_authtype,
1.48 raeburn 621: curr_autharg => $enrollvar->{'autharg'}
622: );
1.32 raeburn 623: my (%authform,$authenitems);
624: $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
625: $authform{'int'} = &Apache::loncommon::authform_internal(%param);
626: $authform{'loc'} = &Apache::loncommon::authform_local(%param);
627: foreach my $item ('krb','int','loc') {
628: if ($authform{$item} ne '') {
629: $authenitems .= $authform{$item}.'<br />';
630: }
1.1 raeburn 631: }
1.48 raeburn 632: return($javascript_validations,$authenitems);
1.1 raeburn 633: }
634:
635: sub modify_course {
1.30 raeburn 636: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1.48 raeburn 637: my %longtype = &course_settings_descrip($type);
638: my @items = ('internal.courseowner','description');
639: unless ($type eq 'Community') {
640: push(@items,('internal.coursecode','internal.authtype','internal.autharg',
641: 'internal.sectionnums','internal.crosslistings'));
1.1 raeburn 642: }
1.48 raeburn 643: my %settings = &Apache::lonnet::get('environment',\@items,$cdom,$cnum);
644: my $description = $settings{'description'};
645: my ($ccrole,$response,$chgresponse,$nochgresponse,$reply,%currattr,%newattr,%cenv,%changed,
646: @changes,@nochanges,@sections,@xlists,@warnings);
647: my @modifiable_params = &get_dc_settable($type);
1.28 raeburn 648: foreach my $param (@modifiable_params) {
1.48 raeburn 649: $currattr{$param} = $settings{'internal.'.$param};
1.1 raeburn 650: }
1.48 raeburn 651: if ($type eq 'Community') {
652: %changed = ( owner => 0 );
653: $ccrole = 'co';
654: } else {
655: %changed = ( code => 0,
656: owner => 0,
657: );
658: $ccrole = 'cc';
659: unless ($settings{'internal.sectionnums'} eq '') {
660: if ($settings{'internal.sectionnums'} =~ m/,/) {
661: @sections = split/,/,$settings{'internal.sectionnums'};
662: } else {
663: $sections[0] = $settings{'internal.sectionnums'};
664: }
665: }
666: unless ($settings{'internal.crosslistings'} eq'') {
667: if ($settings{'internal.crosslistings'} =~ m/,/) {
668: @xlists = split/,/,$settings{'internal.crosslistings'};
669: } else {
670: $xlists[0] = $settings{'internal.crosslistings'};
671: }
672: }
673: if ($env{'form.login'} eq 'krb') {
674: $newattr{'authtype'} = $env{'form.login'};
675: $newattr{'authtype'} .= $env{'form.krbver'};
676: $newattr{'autharg'} = $env{'form.krbarg'};
677: } elsif ($env{'form.login'} eq 'int') {
678: $newattr{'authtype'} ='internal';
679: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
680: $newattr{'autharg'} = $env{'form.intarg'};
681: }
682: } elsif ($env{'form.login'} eq 'loc') {
683: $newattr{'authtype'} = 'localauth';
684: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
685: $newattr{'autharg'} = $env{'form.locarg'};
686: }
687: }
688: if ( $newattr{'authtype'}=~ /^krb/) {
689: if ($newattr{'autharg'} eq '') {
690: push(@warnings,
691: &mt('As you did not include the default Kerberos domain'
1.45 bisitz 692: .' to be used for authentication in this class, the'
693: .' institutional data used by the automated'
694: .' enrollment process must include the Kerberos'
1.48 raeburn 695: .' domain for each new student.'));
696: }
697: }
698:
699: if ( exists($env{'form.coursecode'}) ) {
700: $newattr{'coursecode'}=$env{'form.coursecode'};
701: unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
702: $changed{'code'} = 1;
703: }
1.1 raeburn 704: }
705: }
706:
1.16 albertel 707: if ( exists($env{'form.courseowner'}) ) {
708: $newattr{'courseowner'}=$env{'form.courseowner'};
1.14 raeburn 709: unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
1.38 raeburn 710: $changed{'owner'} = 1;
1.1 raeburn 711: }
712: }
1.48 raeburn 713:
1.38 raeburn 714: if ($changed{'owner'} || $changed{'code'}) {
715: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
716: undef,undef,'.');
717: if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
1.48 raeburn 718: if ($changed{'code'}) {
719: $crsinfo{$env{'form.pickedcourse'}}{'inst_code'} = $env{'form.coursecode'};
720: }
721: if ($changed{'owner'}) {
722: $crsinfo{$env{'form.pickedcourse'}}{'owner'} = $env{'form.courseowner'};
723: }
1.38 raeburn 724: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
725: my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
726: }
1.14 raeburn 727: }
1.28 raeburn 728: foreach my $param (@modifiable_params) {
729: if ($currattr{$param} eq $newattr{$param}) {
730: push(@nochanges,$param);
1.1 raeburn 731: } else {
1.48 raeburn 732: $cenv{'internal.'.$param} = $newattr{$param};
1.28 raeburn 733: push(@changes,$param);
1.1 raeburn 734: }
735: }
736: if (@changes > 0) {
1.48 raeburn 737: $chgresponse = &mt("The following settings have been changed:<br/><ul>");
1.1 raeburn 738: }
1.48 raeburn 739: if (@nochanges > 0) {
740: $nochgresponse = &mt("The following settings remain unchanged:<br/><ul>");
1.1 raeburn 741: }
1.33 raeburn 742: if (@changes > 0) {
1.28 raeburn 743: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1.1 raeburn 744: if ($putreply !~ /^ok$/) {
1.48 raeburn 745: $response = '<p class="LC_error">'.
746: &mt('There was a problem processing your requested changes.').'<br />';
747: if ($type eq 'Community') {
748: $response .= &mt('Settings for this community have been left unchanged.');
749: } else {
750: $response .= &mt('Settings for this course have been left unchanged.');
751: }
752: $response .= '<br/>'.&mt('Error: ').$putreply.'</p>';
1.1 raeburn 753: } else {
1.28 raeburn 754: foreach my $attr (@modifiable_params) {
1.48 raeburn 755: if (grep/^\Q$attr\E$/,@changes) {
756: $chgresponse .= '<li>'.$longtype{$attr}.' '.&mt('now set to:').' "'.$newattr{$attr}.'".</li>';
1.1 raeburn 757: } else {
1.48 raeburn 758: $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to:').' "'.$currattr{$attr}.'".</li>';
1.1 raeburn 759: }
760: }
1.48 raeburn 761: if (($type ne 'Community') && ($changed{'code'} || $changed{'owner'})) {
1.1 raeburn 762: if ( $newattr{'courseowner'} eq '') {
1.48 raeburn 763: push(@warnings,&mt('There is no owner associated with this LON-CAPA course.').
764: '<br />'.&mt('If automated enrollment at your institution requires validation of course owners, automated enrollment will fail.'));
1.1 raeburn 765: } else {
766: if (@sections > 0) {
1.38 raeburn 767: if ($changed{'code'}) {
1.2 raeburn 768: foreach my $sec (@sections) {
769: if ($sec =~ m/^(.+):/) {
1.48 raeburn 770: my $instsec = $1;
1.8 raeburn 771: my $inst_course_id = $newattr{'coursecode'}.$1;
1.28 raeburn 772: my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
1.7 raeburn 773: if ($course_check eq 'ok') {
1.28 raeburn 774: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
1.48 raeburn 775: unless ($outcome eq 'ok') {
776:
777: 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 778: }
779: } else {
1.48 raeburn 780: 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 781: }
782: } else {
1.48 raeburn 783: 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 784: }
785: }
1.38 raeburn 786: } elsif ($changed{'owner'}) {
1.4 raeburn 787: foreach my $sec (@sections) {
788: if ($sec =~ m/^(.+):/) {
1.48 raeburn 789: my $instsec = $1;
790: my $inst_course_id = $newattr{'coursecode'}.$instsec;
1.28 raeburn 791: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
1.4 raeburn 792: unless ($outcome eq 'ok') {
1.48 raeburn 793: 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 794: }
795: } else {
1.48 raeburn 796: 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 797: }
798: }
799: }
1.1 raeburn 800: } else {
1.48 raeburn 801: 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 802: }
1.38 raeburn 803: if ( (@xlists > 0) && ($changed{'owner'}) ) {
1.1 raeburn 804: foreach my $xlist (@xlists) {
805: if ($xlist =~ m/^(.+):/) {
1.48 raeburn 806: my $instxlist = $1;
807: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$instxlist,$newattr{'courseowner'});
1.1 raeburn 808: unless ($outcome eq 'ok') {
1.48 raeburn 809: 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 810: }
1.28 raeburn 811: }
1.1 raeburn 812: }
813: }
814: }
815: }
816: }
1.2 raeburn 817: } else {
1.28 raeburn 818: foreach my $attr (@modifiable_params) {
1.48 raeburn 819: $nochgresponse .= '<li>'.$longtype{$attr}.' '.&mt('still set to').' "'.$currattr{$attr}.'".</li>';
1.2 raeburn 820: }
1.1 raeburn 821: }
822:
823: if (@changes > 0) {
824: $chgresponse .= "</ul><br/><br/>";
825: }
826: if (@nochanges > 0) {
827: $nochgresponse .= "</ul><br/><br/>";
828: }
1.48 raeburn 829: my ($warning,$numwarnings);
830: my $numwarnings = scalar(@warnings);
831: if ($numwarnings) {
832: $warning = &mt('The following [quant,_1,warning was,warnings were] generated when applying your changes to automated enrollment:',$numwarnings).'<p><ul>';
833: foreach my $warn (@warnings) {
834: $warning .= '<li><span class="LC_warning">'.$warn.'</span></li>';
835: }
836: $warning .= '</ul></p>';
1.1 raeburn 837: }
1.48 raeburn 838: if ($response) {
839: $reply = $response;
840: } else {
1.1 raeburn 841: $reply = $chgresponse.$nochgresponse.$warning;
842: }
1.48 raeburn 843: &print_header($r,$type);
844: my $mainheader = &modifiable_only_title($type);
845: $reply = '<h3>'.$mainheader.' <span class="LC_nobreak">'.$cdesc.'</span></h3>'."\n".
846: '<p>'.$reply.'</p>'."\n".
1.28 raeburn 847: '<form action="/adm/modifycourse" method="post" name="processparms">'.
848: &hidden_form_elements().
1.48 raeburn 849: '<a href="javascript:changePage(document.processparms,'."'menu'".')">'.
850: &mt('Pick another action').'</a>';
851: if ($numwarnings) {
852: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
853: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
854: '=1&destinationurl=/adm/populate','&<>"');
855:
856: $reply .= '<br /><a href="'.$escuri.'">'.
857: &mt('Go to Automated Enrollment Manager for course').'</a>';
858: }
859: $reply .= '</form>';
1.3 raeburn 860: $r->print($reply);
1.28 raeburn 861: return;
862: }
863:
864: sub modify_quota {
1.48 raeburn 865: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
866: &print_header($r,$type);
867: $r->print('<form action="/adm/modifycourse" method="post" name="processquota">'."\n".
868: '<h3>'.&mt('Disk space for storage of group portfolio files for:').
869: ' <span class="LC_nobreak">'.$cdesc.'</span></h3><br />');
1.28 raeburn 870: my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
871: my $defaultquota = 20;
872: if ($env{'form.coursequota'} ne '') {
873: my $newquota = $env{'form.coursequota'};
874: if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
875: $newquota = $1;
876: if ($oldsettings{'internal.coursequota'} eq $env{'form.coursequota'}) {
1.48 raeburn 877: $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as [_1] Mb.',$env{'form.coursequota'}));
1.28 raeburn 878: } else {
879: my %cenv = (
880: 'internal.coursequota' => $env{'form.coursequota'},
881: );
882: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
883: $cnum);
884: if (($oldsettings{'internal.coursequota'} eq '') &&
885: ($env{'form.coursequota'} == $defaultquota)) {
1.48 raeburn 886: if ($type eq 'Community') {
887: $r->print(&mt('The disk space allocated for group portfolio files in this community is the default quota for this domain: [_1] Mb.',$defaultquota));
888: } else {
889: $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain: [_1] Mb.',$defaultquota));
890: }
1.28 raeburn 891: } else {
892: if ($putreply eq 'ok') {
893: my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
1.48 raeburn 894: $r->print(&mt('The disk space allocated for group portfolio files is now: [_1] Mb.',$updatedsettings{'internal.coursequota'}));
1.28 raeburn 895: my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
896: if ($usage >= $updatedsettings{'internal.coursequota'}) {
897: my $newoverquota;
898: if ($usage < $oldsettings{'internal.coursequota'}) {
899: $newoverquota = 'now';
900: }
1.48 raeburn 901: $r->print('<p>');
902: if ($type eq 'Community') {
903: $r->print(&mt('Disk usage [_1] exceeds the quota for this community.',$newoverquota).' '.
904: &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.'));
905: } else {
906: $r->print(&mt('Disk usage [_1] exceeds the quota for this course.',$newoverquota).' '.
907: &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.'));
908: }
909: $r->print('</p>');
1.28 raeburn 910: }
911: } else {
1.48 raeburn 912: $r->print(&mt('An error occurred storing the quota for group portfolio files: ').
913: $putreply);
1.28 raeburn 914: }
915: }
916: }
917: } else {
918: $r->print(&mt('The new quota requested contained invalid characters, so the quota is unchanged.'));
919: }
920: }
1.48 raeburn 921: $r->print('<p>'.
922: '<a href="javascript:changePage(document.processquota,'."'menu'".')">'.
923: &mt('Pick another action').'</a>');
1.28 raeburn 924: $r->print(&hidden_form_elements().'</form>');
925: return;
1.1 raeburn 926: }
927:
1.38 raeburn 928: sub modify_catsettings {
1.48 raeburn 929: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
930: &print_header($r,$type);
931: my ($ccrole,%desc);
932: if ($type eq 'Community') {
933: $desc{'hidefromcat'} = &mt('Excluded from community catalog');
934: $desc{'categories'} = &mt('Assigned categories for this community');
935: $ccrole = 'co';
936: } else {
937: $desc{'hidefromcat'} = &mt('Excluded from course catalog');
938: $desc{'categories'} = &mt('Assigned categories for this course');
939: $ccrole = 'cc';
940: }
1.38 raeburn 941: $r->print('
942: <form action="/adm/modifycourse" method="post" name="processcat">
943: <h3>'.&mt('Category settings').'</h3>');
944: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
1.49 ! raeburn 945: my @cat_params = &catalog_settable($domconf{'coursecategories'},$type);
1.38 raeburn 946: if (@cat_params > 0) {
947: my (%cenv,@changes,@nochanges);
948: my %currsettings =
949: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
950: my (@newcategories,%showitem);
951: if (grep(/^togglecats$/,@cat_params)) {
952: if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) {
953: push(@changes,'hidefromcat');
954: $cenv{'hidefromcat'} = $env{'form.hidefromcat'};
955: } else {
956: push(@nochanges,'hidefromcat');
957: }
958: if ($env{'form.hidefromcat'} eq 'yes') {
959: $showitem{'hidefromcat'} = '"'.&mt('Yes')."'";
960: } else {
961: $showitem{'hidefromcat'} = '"'.&mt('No').'"';
962: }
963: }
964: if (grep(/^categorize$/,@cat_params)) {
965: my (@cats,@trails,%allitems,%idx,@jsarray);
966: if (ref($domconf{'coursecategories'}) eq 'HASH') {
967: my $cathash = $domconf{'coursecategories'}{'cats'};
968: if (ref($cathash) eq 'HASH') {
969: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
970: \%allitems,\%idx,\@jsarray);
971: }
972: }
973: @newcategories = &Apache::loncommon::get_env_multiple('form.usecategory');
974: if (@newcategories == 0) {
975: $showitem{'categories'} = '"'.&mt('None').'"';
976: } else {
977: $showitem{'categories'} = '<ul>';
978: foreach my $item (@newcategories) {
979: $showitem{'categories'} .= '<li>'.$trails[$allitems{$item}].'</li>';
980: }
981: $showitem{'categories'} .= '</ul>';
982: }
983: my $catchg = 0;
984: if ($currsettings{'categories'} ne '') {
985: my @currcategories = split('&',$currsettings{'categories'});
986: foreach my $cat (@currcategories) {
987: if (!grep(/^\Q$cat\E$/,@newcategories)) {
988: $catchg = 1;
989: last;
990: }
991: }
992: if (!$catchg) {
993: foreach my $cat (@newcategories) {
994: if (!grep(/^\Q$cat\E$/,@currcategories)) {
995: $catchg = 1;
996: last;
997: }
998: }
999: }
1000: } else {
1001: if (@newcategories > 0) {
1002: $catchg = 1;
1003: }
1004: }
1005: if ($catchg) {
1006: $cenv{'categories'} = join('&',@newcategories);
1007: push(@changes,'categories');
1008: } else {
1009: push(@nochanges,'categories');
1010: }
1011: if (@changes > 0) {
1012: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1013: if ($putreply eq 'ok') {
1014: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
1015: $cnum,undef,undef,'.');
1016: if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
1017: if (grep(/^hidefromcat$/,@changes)) {
1018: $crsinfo{$env{'form.pickedcourse'}}{'hidefromcat'} = $env{'form.hidefromcat'};
1019: }
1020: if (grep(/^categories$/,@changes)) {
1021: $crsinfo{$env{'form.pickedcourse'}}{'categories'} = $cenv{'categories'};
1022: }
1023: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
1024: my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
1025: }
1.48 raeburn 1026: $r->print(&mt('The following changes occurred:').'<ul>');
1.38 raeburn 1027: foreach my $item (@changes) {
1.48 raeburn 1028: $r->print('<li>'.&mt('[_1] now set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38 raeburn 1029: }
1030: $r->print('</ul><br />');
1031: }
1032: }
1033: if (@nochanges > 0) {
1.48 raeburn 1034: $r->print(&mt('The following were unchanged:').'<ul>');
1.38 raeburn 1035: foreach my $item (@nochanges) {
1.48 raeburn 1036: $r->print('<li>'.&mt('[_1] still set to: [_2]',$desc{$item},$showitem{$item}).'</li>');
1.38 raeburn 1037: }
1038: $r->print('</ul>');
1039: }
1040: }
1041: } else {
1.48 raeburn 1042: my $newrole = $ccrole.'./'.$cdom.'/'.$cnum;
1043: my $escuri = &HTML::Entities::encode('/adm/roles?selectrole=1&'.$newrole.
1044: '=1&destinationurl=/adm/courseprefs','&<>"');
1045: if ($type eq 'Community') {
1046: $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 />');
1047: } else {
1048: $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 />');
1049: }
1.38 raeburn 1050: }
1051: $r->print('<br />'."\n".
1052: '<a href="javascript:changePage(document.processcat,'."'menu'".')">'.
1.48 raeburn 1053: &mt('Pick another action').'</a>');
1.38 raeburn 1054: $r->print(&hidden_form_elements().'</form>');
1055: return;
1056: }
1057:
1.1 raeburn 1058: sub print_header {
1.48 raeburn 1059: my ($r,$type,$javascript_validations) = @_;
1.28 raeburn 1060: my $phase = "start";
1061: if ( exists($env{'form.phase'}) ) {
1062: $phase = $env{'form.phase'};
1063: }
1064: my $js = qq|
1065: <script type="text/javascript">
1066: function changePage(formname,newphase) {
1067: formname.phase.value = newphase;
1068: if (newphase == 'processparms') {
1069: return;
1.1 raeburn 1070: }
1.28 raeburn 1071: formname.submit();
1072: }
1073: </script>
1074: |;
1075: if ($phase eq 'setparms') {
1076: $js .= qq|
1077: <script type="text/javascript">
1078: $javascript_validations
1079: </script>
1080: |;
1081: } elsif ($phase eq 'courselist') {
1082: $js .= qq|
1083: <script type="text/javascript">
1084: function gochoose(cname,cdom,cdesc) {
1085: document.courselist.pickedcourse.value = cdom+'_'+cname;
1086: document.courselist.submit();
1087: }
1088: </script>
1089: |;
1090: } elsif ($phase eq 'setquota') {
1091: $js .= <<'ENDSCRIPT';
1092: <script type="text/javascript">
1093: function verify_quota(formname) {
1094: var newquota = formname.coursequota.value;
1095: var num_reg = /^\s*(\d+\.?\d*|\.\d+)\s*$/;
1096: if (num_reg.test(newquota)) {
1097: changePage(formname,'processquota');
1.1 raeburn 1098: } else {
1.28 raeburn 1099: alert("The quota you entered contained invalid characters.\nYou must enter a number");
1.1 raeburn 1100: }
1.28 raeburn 1101: return;
1102: }
1103: </script>
1104: ENDSCRIPT
1.1 raeburn 1105: }
1.37 raeburn 1106: my $starthash;
1107: if ($env{'form.phase'} eq 'ccrole') {
1108: $starthash = {
1109: add_entries => {'onload' => "javascript:document.ccrole.submit();"},
1110: };
1111: }
1.48 raeburn 1112: $r->print(&Apache::loncommon::start_page('View/Modify Course/Community Settings',
1.37 raeburn 1113: $js,$starthash));
1.48 raeburn 1114: my $bread_text = "View/Modify Courses/Communities";
1115: if ($type eq 'Community') {
1116: $bread_text = 'Community Settings';
1.41 raeburn 1117: } else {
1.48 raeburn 1118: $bread_text = 'Course Settings';
1.41 raeburn 1119: }
1.48 raeburn 1120: $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
1.5 raeburn 1121: return;
1.1 raeburn 1122: }
1123:
1124: sub print_footer {
1.23 albertel 1125: my ($r) = @_;
1126: $r->print('<br />'.&Apache::loncommon::end_page());
1.5 raeburn 1127: return;
1.3 raeburn 1128: }
1129:
1130: sub check_course {
1.28 raeburn 1131: my ($r,$dom,$domdesc) = @_;
1132: my ($ok_course,$description,$instcode,$owner);
1.35 raeburn 1133: my %args = (
1134: one_time => 1,
1135: );
1136: my %coursehash =
1137: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
1138: my $cnum = $coursehash{'num'};
1139: my $cdom = $coursehash{'domain'};
1140: if ($cdom eq $dom) {
1141: my $description;
1142: my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
1.38 raeburn 1143: $cnum,undef,undef,'.');
1.35 raeburn 1144: if (keys(%courseIDs) > 0) {
1145: $ok_course = 'ok';
1146: my ($instcode,$owner);
1147: if (ref($courseIDs{$cdom.'_'.$cnum}) eq 'HASH') {
1148: $description = $courseIDs{$cdom.'_'.$cnum}{'description'};
1149: $instcode = $courseIDs{$cdom.'_'.$cnum}{'inst_code'};
1150: $owner = $courseIDs{$cdom.'_'.$cnum}{'owner'};
1151: } else {
1152: ($description,$instcode,$owner) =
1153: split(/:/,$courseIDs{$cdom.'_'.$cnum});
1154: }
1155: $description = &unescape($description);
1156: $instcode = &unescape($instcode);
1157: if ($instcode) {
1158: $description .= " ($instcode)";
1.5 raeburn 1159: }
1.35 raeburn 1160: return ($ok_course,$description);
1.3 raeburn 1161: }
1162: }
1.1 raeburn 1163: }
1164:
1.28 raeburn 1165: sub course_settings_descrip {
1.48 raeburn 1166: my ($type) = @_;
1167: my %longtype;
1168: if ($type eq 'Community') {
1169: %longtype = &Apache::lonlocal::texthash(
1170: 'courseowner' => "Username:domain of community owner",
1171: );
1172:
1173: } else {
1174: %longtype = &Apache::lonlocal::texthash(
1.28 raeburn 1175: 'authtype' => 'Default authentication method',
1176: 'autharg' => 'Default authentication parameter',
1177: 'autoadds' => 'Automated adds',
1178: 'autodrops' => 'Automated drops',
1179: 'autostart' => 'Date of first automated enrollment',
1180: 'autoend' => 'Date of last automated enrollment',
1181: 'default_enrollment_start_date' => 'Date of first student access',
1182: 'default_enrollment_end_date' => 'Date of last student access',
1183: 'coursecode' => 'Official course code',
1184: 'courseowner' => "Username:domain of course owner",
1185: 'notifylist' => 'Course Coordinators to be notified of enrollment changes',
1.48 raeburn 1186: 'sectionnums' => 'Course section number:LON-CAPA section',
1187: 'crosslistings' => 'Crosslisted class:LON-CAPA section',
1188: );
1189: }
1.28 raeburn 1190: return %longtype;
1191: }
1192:
1193: sub hidden_form_elements {
1194: my $hidden_elements =
1.46 raeburn 1195: &Apache::lonhtmlcommon::echo_form_input(['gosearch','updater','coursecode',
1.37 raeburn 1196: 'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
1.38 raeburn 1197: 'locarg','krbarg','krbver','counter','hidefromcat','usecategory'])."\n".
1.37 raeburn 1198: '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
1.28 raeburn 1199: return $hidden_elements;
1200: }
1.1 raeburn 1201:
1202: sub handler {
1203: my $r = shift;
1204: if ($r->header_only) {
1205: &Apache::loncommon::content_type($r,'text/html');
1206: $r->send_http_header;
1207: return OK;
1208: }
1.28 raeburn 1209: my $dom = $env{'request.role.domain'};
1.31 albertel 1210: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.28 raeburn 1211: if (&Apache::lonnet::allowed('ccc',$dom)) {
1.1 raeburn 1212: &Apache::loncommon::content_type($r,'text/html');
1213: $r->send_http_header;
1214:
1.28 raeburn 1215: &Apache::lonhtmlcommon::clear_breadcrumbs();
1216:
1217: my $phase = $env{'form.phase'};
1.46 raeburn 1218: if ($env{'form.updater'}) {
1219: $phase = '';
1220: }
1.37 raeburn 1221: if ($phase eq '') {
1222: &Apache::lonhtmlcommon::add_breadcrumb
1.28 raeburn 1223: ({href=>"/adm/modifycourse",
1.48 raeburn 1224: text=>"Course/Community search"});
1.28 raeburn 1225: &print_course_search_page($r,$dom,$domdesc);
1.1 raeburn 1226: } else {
1.37 raeburn 1227: my $firstform = $phase;
1228: if ($phase eq 'courselist') {
1229: $firstform = 'filterpicker';
1.48 raeburn 1230: }
1231: my $choose_text;
1232: my $type = $env{'form.type'};
1233: if ($type eq '') {
1234: $type = 'Course';
1235: }
1236: if ($type eq 'Community') {
1237: $choose_text = "Choose a community";
1238: } else {
1239: $choose_text = "Choose a course";
1.37 raeburn 1240: }
1.28 raeburn 1241: &Apache::lonhtmlcommon::add_breadcrumb
1.37 raeburn 1242: ({href=>"javascript:changePage(document.$firstform,'')",
1.48 raeburn 1243: text=>"Course/Community search"},
1.37 raeburn 1244: {href=>"javascript:changePage(document.$phase,'courselist')",
1.48 raeburn 1245: text=>$choose_text});
1.28 raeburn 1246: if ($phase eq 'courselist') {
1247: &print_course_selection_page($r,$dom,$domdesc);
1248: } else {
1249: my ($checked,$cdesc) = &check_course($r,$dom,$domdesc);
1250: if ($checked eq 'ok') {
1.48 raeburn 1251: my $enter_text;
1252: if ($type eq 'Community') {
1253: $enter_text = 'Enter community';
1254: } else {
1255: $enter_text = 'Enter course';
1256: }
1.28 raeburn 1257: if ($phase eq 'menu') {
1.37 raeburn 1258: &Apache::lonhtmlcommon::add_breadcrumb
1259: ({href=>"javascript:changePage(document.$phase,'menu')",
1260: text=>"Pick action"});
1.48 raeburn 1261: &print_modification_menu($r,$cdesc,$domdesc,$dom,$type);
1.37 raeburn 1262: } elsif ($phase eq 'ccrole') {
1263: &Apache::lonhtmlcommon::add_breadcrumb
1264: ({href=>"javascript:changePage(document.$phase,'ccrole')",
1.48 raeburn 1265: text=>$enter_text});
1266: &print_ccrole_selected($r,$type);
1.28 raeburn 1267: } else {
1.37 raeburn 1268: &Apache::lonhtmlcommon::add_breadcrumb
1269: ({href=>"javascript:changePage(document.$phase,'menu')",
1270: text=>"Pick action"});
1.28 raeburn 1271: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
1272: if ($phase eq 'setquota') {
1273: &Apache::lonhtmlcommon::add_breadcrumb
1274: ({href=>"javascript:changePage(document.$phase,'$phase')",
1275: text=>"Set quota"});
1.38 raeburn 1276: &print_setquota($r,$cdom,$cnum,$cdesc,$type);
1.28 raeburn 1277: } elsif ($phase eq 'processquota') {
1278: &Apache::lonhtmlcommon::add_breadcrumb
1279: ({href=>"javascript:changePage(document.$phase,'setquota')",
1280: text=>"Set quota"});
1281: &Apache::lonhtmlcommon::add_breadcrumb
1282: ({href=>"javascript:changePage(document.$phase,'$phase')",
1283: text=>"Result"});
1.48 raeburn 1284: &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.28 raeburn 1285: } elsif ($phase eq 'viewparms') {
1286: &Apache::lonhtmlcommon::add_breadcrumb
1287: ({href=>"javascript:changePage(document.$phase,'viewparms')",
1288: text=>"Display settings"});
1289: &print_settings_display($r,$cdom,$cnum,$cdesc,$type);
1290: } elsif ($phase eq 'setparms') {
1291: &Apache::lonhtmlcommon::add_breadcrumb
1292: ({href=>"javascript:changePage(document.$phase,'$phase')",
1293: text=>"Change settings"});
1.48 raeburn 1294: &print_course_modification_page($r,$cdom,$cnum,$cdesc,$type);
1.28 raeburn 1295: } elsif ($phase eq 'processparms') {
1296: &Apache::lonhtmlcommon::add_breadcrumb
1297: ({href=>"javascript:changePage(document.$phase,'setparms')",
1298: text=>"Change settings"});
1299: &Apache::lonhtmlcommon::add_breadcrumb
1300: ({href=>"javascript:changePage(document.$phase,'$phase')",
1301: text=>"Result"});
1.30 raeburn 1302: &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.38 raeburn 1303: } elsif ($phase eq 'catsettings') {
1304: &Apache::lonhtmlcommon::add_breadcrumb
1305: ({href=>"javascript:changePage(document.$phase,'$phase')",
1306: text=>"Catalog settings"});
1307: &print_catsettings($r,$cdom,$cnum,$cdesc,$type);
1308: } elsif ($phase eq 'processcat') {
1309: &Apache::lonhtmlcommon::add_breadcrumb
1310: ({href=>"javascript:changePage(document.$phase,'catsettings')",
1311: text=>"Catalog settings"});
1312: &Apache::lonhtmlcommon::add_breadcrumb
1313: ({href=>"javascript:changePage(document.$phase,'$phase')",
1314: text=>"Result"});
1.48 raeburn 1315: &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.28 raeburn 1316: }
1317: }
1318: } else {
1.48 raeburn 1319: $r->print('<span class="LC_error">');
1320: if ($type eq 'Community') {
1321: $r->print(&mt('The course you selected is not a valid course in this domain'));
1322: } else {
1323: $r->print(&mt('The community you selected is not a valid community in this domain'));
1324: }
1325: $r->print(" ($domdesc)</span>");
1.28 raeburn 1326: }
1327: }
1.1 raeburn 1328: }
1.28 raeburn 1329: &print_footer($r);
1.1 raeburn 1330: } else {
1.16 albertel 1331: $env{'user.error.msg'}=
1.48 raeburn 1332: "/adm/modifycourse:ccc:0:0:Cannot modify course/community settings";
1.1 raeburn 1333: return HTTP_NOT_ACCEPTABLE;
1334: }
1335: return OK;
1336: }
1337:
1338: 1;
1339: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>