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