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