Annotation of loncom/interface/lonmodifycourse.pm, revision 1.45
1.20 albertel 1: # The LearningOnline Network with CAPA
1.28 raeburn 2: # handler for DC-only modifiable course settings
1.20 albertel 3: #
1.45 ! bisitz 4: # $Id: lonmodifycourse.pm,v 1.44 2009/05/08 17:22:17 raeburn Exp $
1.20 albertel 5: #
1.3 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 raeburn 28: package Apache::lonmodifycourse;
29:
30: use strict;
31: use Apache::Constants qw(:common :http);
32: use Apache::lonnet;
33: use Apache::loncommon;
1.28 raeburn 34: use Apache::lonhtmlcommon;
1.1 raeburn 35: use Apache::lonlocal;
1.36 raeburn 36: use Apache::lonuserutils;
1.28 raeburn 37: use Apache::lonpickcourse;
1.1 raeburn 38: use LONCAPA::Enrollment;
39: use lib '/home/httpd/lib/perl';
1.25 www 40: use LONCAPA;
1.1 raeburn 41:
1.28 raeburn 42: sub get_dc_settable {
43: return ('courseowner','coursecode','authtype','autharg');
44: }
45:
1.38 raeburn 46: sub catalog_settable {
47: my ($confhash) = @_;
48: my @settable;
49: if (ref($confhash) eq 'HASH') {
50: if ($confhash->{'togglecats'} ne 'crs') {
51: push(@settable,'togglecats');
52: }
53: if ($confhash->{'categorize'} ne 'crs') {
54: push(@settable,'categorize');
55: }
56: } else {
57: push(@settable,('togglecats','categorize'));
58: }
59: return @settable;
60: }
61:
1.28 raeburn 62: sub get_enrollment_settings {
63: my ($cdom,$cnum) = @_;
64: my %settings = &Apache::lonnet::dump('environment',$cdom,$cnum);
65: my %enrollvar;
66: $enrollvar{'autharg'} = '';
67: $enrollvar{'authtype'} = '';
1.1 raeburn 68: my %lt=&Apache::lonlocal::texthash(
1.28 raeburn 69: 'noen' => "No end date",
1.1 raeburn 70: );
1.28 raeburn 71: foreach my $item (keys %settings) {
72: if ($item =~ m/^internal\.(.+)$/) {
73: my $type = $1;
74: if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
75: if ($settings{$item} == 1) {
76: $enrollvar{$type} = "ON";
77: } else {
78: $enrollvar{$type} = "OFF";
1.10 raeburn 79: }
1.28 raeburn 80: } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
81: if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
82: $enrollvar{$type} = $lt{'noen'};
83: } else {
84: $enrollvar{$type} = localtime($settings{$item});
1.14 raeburn 85: }
1.30 raeburn 86: } elsif ($type eq "sectionnums") {
1.28 raeburn 87: $enrollvar{$type} = $settings{$item};
88: $enrollvar{$type} =~ s/,/, /g;
89: } elsif ($type eq "authtype"
90: || $type eq "autharg" || $type eq "coursecode"
91: || $type eq "crosslistings") {
92: $enrollvar{$type} = $settings{$item};
93: } elsif ($type eq 'courseowner') {
94: if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
95: $enrollvar{$type} = $settings{$item};
96: } else {
97: if ($settings{$item} ne '') {
98: $enrollvar{$type} = $settings{$item}.':'.$cdom;
1.26 raeburn 99: }
1.1 raeburn 100: }
1.28 raeburn 101: }
102: } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
103: my $type = $1;
104: if ( ($type eq 'end') && ($settings{$item} == 0) ) {
105: $enrollvar{$item} = $lt{'noen'};
106: } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
107: $enrollvar{$item} = 'When enrolled';
108: } else {
109: $enrollvar{$item} = localtime($settings{$item});
1.1 raeburn 110: }
111: }
112: }
1.28 raeburn 113: return %enrollvar;
114: }
115:
116: sub print_course_search_page {
117: my ($r,$dom,$domdesc) = @_;
118: &print_header($r);
119: my $filterlist = ['descriptfilter',
120: 'instcodefilter','ownerfilter',
1.44 raeburn 121: 'coursefilter'];
1.28 raeburn 122: my $filter = {};
1.44 raeburn 123: my $numtitles;
1.28 raeburn 124: my $type = 'Course';
125: my $action = '/adm/modifycourse';
126: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
127: my $dctitle = &Apache::lonnet::plaintext('dc');
1.37 raeburn 128: $r->print(
129: '<h3>'.&mt('Search for a course in the [_1] domain',$domdesc).'</h3>'.
1.39 raeburn 130: &mt('Actions available after searching for a course:').'<ul>'.
1.37 raeburn 131: '<li>'.&mt('Enter the course with the role of [_1]',$cctitle).'</li>'."\n".
132: '<li>'.&mt('View or modify course settings which only a [_1] may modify.'
133: ,$dctitle).'</li>'."\n".'</ul>');
1.28 raeburn 134: $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
1.44 raeburn 135: undef,undef,$filter,$action,\$numtitles,'modifycourse'));
1.28 raeburn 136: }
137:
138: sub print_course_selection_page {
139: my ($r,$dom,$domdesc) = @_;
140: &print_header($r);
141:
142: # Criteria for course search
143: my $filterlist = ['descriptfilter',
144: 'instcodefilter','ownerfilter',
145: 'ownerdomfilter','coursefilter'];
146: my %filter;
147: my $type = $env{'form.type'};
1.29 raeburn 148: if ($type eq '') {
149: $type = 'Course';
150: }
1.28 raeburn 151: my $action = '/adm/modifycourse';
152: my $dctitle = &Apache::lonnet::plaintext('dc');
153: $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br /><br />');
154: $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
155: undef,undef,\%filter,$action));
156: $filter{'domainfilter'} = $dom;
157: my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,
158: \%filter);
1.44 raeburn 159: &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,undef,
1.28 raeburn 160: %courses);
1.1 raeburn 161: return;
162: }
163:
1.28 raeburn 164: sub print_modification_menu {
1.38 raeburn 165: my ($r,$cdesc,$domdesc,$dom) = @_;
1.28 raeburn 166: &print_header($r,$cdesc);
1.37 raeburn 167: my $type = 'Course';
168: my $action = '/adm/modifycourse';
169: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
170: my $dctitle = &Apache::lonnet::plaintext('dc');
171: my %lt=&Apache::lonlocal::texthash(
172: 'some' => "Certain settings which control auto-enrollment of students from your institution's student information system.",
173: 'crqo' => 'The total disk space allocated for storage of portfolio files in all groups in a course.',
174: );
1.28 raeburn 175: my @menu =
176: (
1.43 weissno 177: { text => 'Modify quota for group portfolio',
1.28 raeburn 178: phase => 'setquota',
179: },
180: { text => 'Display current settings for automated enrollment',
181: phase => 'viewparms',
182: },
183: { text => 'Modify institutional code, course owner and/or default authentication',
184: phase => 'setparms',
1.38 raeburn 185: },
1.28 raeburn 186: );
1.38 raeburn 187: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$dom);
188: my @additional_params = &catalog_settable($domconf{'coursecategories'});
189: if (@additional_params > 0) {
190: push (@menu, { text => 'Modify course catalog settings for course',
191: phase => 'catsettings',
192: });
193: }
1.28 raeburn 194: my $menu_html = '<h3>'.&mt('View/Modify settings for: ').$cdesc.'</h3>'."\n".
1.37 raeburn 195: &mt('Although almost all course settings can be modified by a [_1], a number of settings exist which only a [_2] may change:',$cctitle,$dctitle).'
196: <ul>
197: <li>'.$lt{'some'}.'</li>
1.38 raeburn 198: <li>'.$lt{'crqo'}.'</li>'."\n";
199: foreach my $item (@additional_params) {
200: if ($item eq 'togglecats') {
201: $menu_html .= ' <li>'.&mt('Hiding a course from the course catalog (can be [_1]configured[_2] to be modifiable in course context)','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
202: } elsif ($item eq 'categorize') {
203: $menu_html .= ' <li>'.&mt('Manual cataloging of a course (can be [_1]configured[_2] to be modifiable in course context)','<a href="/adm/domainprefs?actions=coursecategories&phase=display">','</a>').'</li>'."\n";
204:
205: }
206: }
207: $menu_html .= ' </ul>
1.37 raeburn 208: <form name="menu" method="post" action="'.$action.'" />'."\n".
209: &hidden_form_elements();
210:
1.28 raeburn 211: foreach my $menu_item (@menu) {
212: $menu_html.='<p>';
213: $menu_html.='<font size="+1">';
214: $menu_html.=
215: qq|<a href="javascript:changePage(document.menu,'$menu_item->{'phase'}')">|;
216: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
217: $menu_html.='</p>';
1.3 raeburn 218: }
1.28 raeburn 219:
220: $r->print($menu_html);
221: return;
222: }
223:
1.37 raeburn 224: sub print_ccrole_selected {
225: my ($r,$cdesc,$domdesc) = @_;
226: &print_header($r);
227: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
228: $r->print('<form name="ccrole" method="post" action="/adm/roles">
229: <input type="hidden" name="selectrole" value="1" />
230: <input type="hidden" name="newrole" value="cc./'.$cdom.'/'.$cnum.'" />
231: </form>');
232: }
233:
1.28 raeburn 234: sub print_settings_display {
235: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
236: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
237: my %longtype = &course_settings_descrip();
238: my %lt = &Apache::lonlocal::texthash(
239: 'cset' => "Course setting",
240: 'valu' => "Current value",
241: 'caes' => 'Current automated enrollment settings for ',
242: 'cour' => "Course settings that control automated enrollment in this LON-CAPA course are currently:",
243: 'cose' => "Course settings for LON-CAPA courses that control auto-enrollment based on classlist data available from your institution's student information system fall into two groups:",
244: 'dcon' => "Modifiable by DC only",
245: 'back' => "Back to options page",
246: );
247:
248: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
249: my $dctitle = &Apache::lonnet::plaintext('dc');
250: my @modifiable_params = &get_dc_settable();
251:
252: my $disp_table = &Apache::loncommon::start_data_table()."\n".
253: &Apache::loncommon::start_data_table_header_row()."\n".
254: "<th>$lt{'cset'}</th>\n".
255: "<th>$lt{'valu'}</th>\n".
256: "<th>$lt{'dcon'}</th>\n".
257: &Apache::loncommon::end_data_table_header_row()."\n";
258: foreach my $key (sort(keys(%enrollvar))) {
259: $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
260: "<td>$longtype{$key}</td>\n".
261: "<td>$enrollvar{$key}</td>\n";
262: if (grep(/^\Q$key\E$/,@modifiable_params)) {
263: $disp_table .= '<td>'.&mt('Yes').'</td>'."\n";
264: } else {
265: $disp_table .= '<td>'.&mt('No').'</td>'."\n";
266: }
267: $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
1.3 raeburn 268: }
1.28 raeburn 269: $disp_table .= &Apache::loncommon::end_data_table()."\n";
270: &print_header($r,$cdesc);
271: $r->print('
1.41 raeburn 272: <h3>'.$lt{'caes'}.$cdesc.'</h3>
1.45 ! bisitz 273: <form action="/adm/modifycourse" method="post" name="viewparms">
1.28 raeburn 274: <p>
1.45 ! bisitz 275: '.$lt{'cose'}.'
! 276: <ul><li>
! 277: '.&mt('Settings that can be modified by a [_1] using the [_2]Automated Enrollment Manager[_3].'
! 278: ,$cctitle,'<a href="/adm/populate">','</a>').'
! 279: </li><li>
! 280: '.&mt('Settings that may only be modified by a [_1] from this menu.',$dctitle).'
! 281: </li></ul>
1.28 raeburn 282: </p><p>
283: '.$lt{'cour'}.'
284: </p><p>
285: '.$disp_table.'
286: </p><p>
287: <a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>
288: <a href="javascript:changePage(document.viewparms,'."'setparms'".')">'.&mt('Modify [_1]-only settings',$dctitle).'</a>'."\n".
1.37 raeburn 289: &hidden_form_elements().
1.45 ! bisitz 290: '</p></form>');
1.28 raeburn 291: }
1.3 raeburn 292:
1.28 raeburn 293: sub print_setquota {
294: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
295: my $dctitle = &Apache::lonnet::plaintext('dc');
296: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
297: my $subdiv = &mt('Although a [_1] will assign the disk quota for each individual group, the size of the quota is constrained by the total disk space allocated by the [_2] for portfolio files in a course.',$cctitle,$dctitle);
298: my %lt = &Apache::lonlocal::texthash(
1.43 weissno 299: 'cquo' => 'Disk space for storage of group portfolio',
1.28 raeburn 300: 'gpqu' => 'Course portfolio files disk space',
301: 'each' => 'Each course group can be assigned a quota for portfolio files uploaded to the group.',
1.42 schafran 302: 'modi' => 'Save',
1.28 raeburn 303: 'back' => "Back to options page",
304: );
305: my %settings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
306: my $coursequota = $settings{'internal.coursequota'};
307: if ($coursequota eq '') {
308: $coursequota = 20;
1.3 raeburn 309: }
1.28 raeburn 310: &print_header($r,$cdesc);
311: my $hidden_elements = &hidden_form_elements();
312: $r->print(<<ENDDOCUMENT);
313: <form action="/adm/modifycourse" method="post" name="setquota">
314: <h3>$lt{'cquo'}.</h3>
315: <p>
316: $lt{'each'}<br />
317: $subdiv
318: </p><p>
319: $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" /> Mb
320: <input type="button" onClick="javascript:verify_quota(this.form)" value="$lt{'modi'}" />
321: </p>
322: $hidden_elements
323: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
324: </form>
325: ENDDOCUMENT
326: return;
327: }
1.3 raeburn 328:
1.38 raeburn 329: sub print_catsettings {
330: my ($r,$cdom,$cnum,$cdesc) = @_;
331: &print_header($r,$cdesc);
332: my %lt = &Apache::lonlocal::texthash(
333: 'back' => 'Back to options page',
334: );
335: $r->print('<form action="/adm/modifycourse" method="post" name="catsettings">'.
336: '<h3>'.&mt('Catalog Settings for Course').'</h3>');
337: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
338: my @cat_params = &catalog_settable($domconf{'coursecategories'});
339: if (@cat_params > 0) {
340: my %currsettings =
341: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
342: if (grep(/^togglecats$/,@cat_params)) {
343: my $excludeon = '';
344: my $excludeoff = ' checked="checked" ';
345: if ($currsettings{'hidefromcat'} eq 'yes') {
346: $excludeon = $excludeoff;
347: $excludeoff = '';
348: }
349: $r->print('<h4>'.&mt('Visibility in Course Catalog').'</h4>'.
1.40 bisitz 350: &mt("Unless excluded, a course is listed in this domain's publicly accessible course catalog, if at least one of the following applies").':<ul>'.
1.38 raeburn 351: '<li>'.&mt('Auto-cataloging is enabled and the course is assigned an institutional code').'</li>'.
352: '<li>'.&mt('The course has been categorized into at least one of the course categories defined for the domain.').'</li></ul>'.
1.39 raeburn 353: &mt('Exclude from course catalog').' <label><input name="hidefromcat" type="radio" value="yes" '.$excludeon.' />'.&mt('Yes').'</label> <label><input name="hidefromcat" type="radio" value="" '.$excludeoff.' />'.&mt('No').'</label><br />');
1.38 raeburn 354: }
355: if (grep(/^categorize$/,@cat_params)) {
356: $r->print('<h4>'.&mt('Categorize Course').'</h4>');
357: if (ref($domconf{'coursecategories'}) eq 'HASH') {
358: my $cathash = $domconf{'coursecategories'}{'cats'};
359: if (ref($cathash) eq 'HASH') {
360: $r->print(&mt('Assign one or more categories to this course.').'<br /><br />'.
361: &Apache::loncommon::assign_categories_table($cathash,
362: $currsettings{'categories'}));
363: } else {
364: $r->print(&mt('No categories defined for this domain'));
365: }
366: } else {
367: $r->print(&mt('No categories defined for this domain'));
368: }
369: $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>');
370: }
371: $r->print('<input type="button" name="chgcatsettings" value="'.
372: &mt('Save').'" onclick="javascript:changePage(document.catsettings,'."'processcat'".');" />');
373: } else {
374: $r->print('<span class="LC_warning">'.&mt('Catalog settings in this domain are set in course context via "Set Course Environment".').'</span><br /><br />'."\n".
375: '<a href="javascript:changePage(document.catsettings,'."'menu'".');">'.
376: $lt{'back'}.'</a>');
377: }
378: $r->print(&hidden_form_elements().'</form>'."\n");
379: return;
380: }
381:
1.28 raeburn 382: sub print_course_modification_page {
383: my ($r,$cdom,$cnum,$cdesc,$domdesc) = @_;
384: my %longtype = &course_settings_descrip();
385: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.1 raeburn 386: my $ownertable;
1.2 raeburn 387: my %lt=&Apache::lonlocal::texthash(
388: 'actv' => "Active",
389: 'inac' => "Inactive",
390: 'ccor' => "Course Coordinator",
391: 'noen' => "No end date",
392: 'ownr' => "Owner",
393: 'name' => "Name",
1.26 raeburn 394: 'unme' => "Username:Domain",
1.2 raeburn 395: 'stus' => "Status",
1.43 weissno 396: 'cquo' => "Disk space for storage of group portfolio",
1.28 raeburn 397: 'gpqu' => "Course portfolio files disk space",
398: 'each' => "Each course group can be assigned a quota for portfolio files uploaded to the group.",
1.2 raeburn 399: 'cose' => "Course settings for LON-CAPA courses that control automated student enrollment based on classlist data available from your institution's student information system fall into two groups: (a) settings that can be modified by a Course Coordinator using the ",
400: 'aenm' => "Automated Enrollment Manager",
401: 'andb' => " and (b) settings that may only be modified by a Domain Coordinator via this page.",
402: 'caes' => 'Current automated enrollment settings',
403: 'cour' => "Course settings that control automated enrollment in this LON-CAPA course
404: are currently:",
405: 'nocc' => "There is currently no course owner set for this course. In addition, no active course coordinators from this LON-CAPA domain were found, so you will not be able assign a course owner. If you wish to assign a course owner, it is recommended that you use the 'User Roles' screen to add a course coordinator with a LON-CAPA account in this domain to the course.",
406: 'ccus' => "A course coordinator can use the 'Automated Enrollment Manager' to change
407: all settings except course code, course owner, and default authentication method for students added to your course (who are also new to the LON-CAPA system at this domain).",
408: 'ccod' => "Course Code",
409: 'ccus' => "The course code is used during automated enrollment to map the internal LON-CAPA course ID for this course to the corresponding course section ID(s) used by the office responsible for providing official class lists for courses at your institution.",
410: 'cown' => "Course Owner",
411: 'cous' => "The course owner is used in the retrieval of class lists from your institution's student information system when access to class lists data incorporates validation of instructor status.",
412: 'tabl' => 'The table below contains a list of active course coordinators in this course, who are from this domain',
413: 'usrd' => 'Use the radio buttons to select a different course owner.',
414: 'deam' => "Default Authentication method",
415: 'deus' => "The default authentication method, and default authentication parameter (domain, initial password or argument) are used when automatic enrollment of students in a course requires addition of new user accounts in your domain, and the class list file contains empty entries for the <authtype> and <autharg> properties for the new student. If you choose 'internally authenticated', and leave the initial password field empty, the automated enrollment process will create a randomized password for each new student account that it adds to your LON-CAPA domain.",
1.32 raeburn 416: 'gobt' => "Save",
1.2 raeburn 417: );
418:
1.28 raeburn 419: my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$cdom,$cnum);
1.1 raeburn 420: my @local_ccs = ();
421: my %cc_status = ();
422: my %pname = ();
423: my $active_cc;
1.26 raeburn 424: foreach my $person (@coursepersonnel) {
425: my ($role,$user) = split(/:/,$person,2);
426: $user =~ s/:$//;
427: if (($role eq 'cc') && ($user ne '')) {
428: if (!grep(/^\Q$user\E$/,@local_ccs)) {
429: my ($ccname,$ccdom) = split(/:/,$user);
430: $active_cc =
1.28 raeburn 431: &Apache::loncommon::check_user_status($ccdom,$ccname,$cdom,
432: $cnum,'cc');
1.19 raeburn 433: if ($active_cc eq 'active') {
1.26 raeburn 434: push(@local_ccs,$user);
435: $pname{$user} = &Apache::loncommon::plainname($ccname,$ccdom);
436: $cc_status{$user} = $lt{'actv'};
1.1 raeburn 437: }
438: }
439: }
440: }
1.26 raeburn 441: if ( (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs)) &&
442: ($enrollvar{'courseowner'} ne '') ) {
443: my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
444: push(@local_ccs,$enrollvar{'courseowner'});
445: $pname{$enrollvar{'courseowner'}} =
446: &Apache::loncommon::plainname($owneruname,$ownerdom);
447: $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
1.28 raeburn 448: $cdom,$cnum,'cc');
1.19 raeburn 449: if ($active_cc eq 'active') {
1.2 raeburn 450: $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1 raeburn 451: } else {
1.2 raeburn 452: $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1 raeburn 453: }
454: }
455: my $numlocalcc = @local_ccs;
1.24 albertel 456:
1.2 raeburn 457: my $helplink=&Apache::loncommon::help_open_topic('Modify_Course',&mt("Help on Modifying Courses"));
1.28 raeburn 458: my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
1.2 raeburn 459: my $curr_authtype = '';
460: my $curr_authfield = '';
461: if ($enrollvar{'authtype'} =~ /^krb/) {
462: $curr_authtype = 'krb';
463: } elsif ($enrollvar{'authtype'} eq 'internal' ) {
464: $curr_authtype = 'int';
465: } elsif ($enrollvar{'authtype'} eq 'localauth' ) {
466: $curr_authtype = 'loc';
467: }
468: unless ($curr_authtype eq '') {
469: $curr_authfield = $curr_authtype.'arg';
1.33 raeburn 470: }
1.36 raeburn 471: my $javascript_validations=&Apache::lonuserutils::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield);
1.35 raeburn 472: my %param = ( formname => 'document.'.$env{'form.phase'},
1.1 raeburn 473: kerb_def_dom => $krbdefdom,
1.2 raeburn 474: kerb_def_auth => $krbdef,
475: mode => 'modifycourse',
476: curr_authtype => $curr_authtype,
477: curr_autharg => $enrollvar{'autharg'}
1.1 raeburn 478: );
1.32 raeburn 479: my (%authform,$authenitems);
480: $authform{'krb'} = &Apache::loncommon::authform_kerberos(%param);
481: $authform{'int'} = &Apache::loncommon::authform_internal(%param);
482: $authform{'loc'} = &Apache::loncommon::authform_local(%param);
483: foreach my $item ('krb','int','loc') {
484: if ($authform{$item} ne '') {
485: $authenitems .= $authform{$item}.'<br />';
486: }
487: }
1.1 raeburn 488: if ($numlocalcc == 0) {
1.2 raeburn 489: $ownertable = $lt{'nocc'};
1.1 raeburn 490: }
1.2 raeburn 491:
1.1 raeburn 492: if ($numlocalcc > 0) {
493: @local_ccs = sort @local_ccs;
494: $ownertable = qq(
495: <input type="hidden" name="numlocalcc" value="$numlocalcc" />
496: <table>
497: <tr>
1.28 raeburn 498: <td>$lt{'tabl'} - $cdom ($domdesc). $lt{'usrd'}
1.1 raeburn 499: </td>
500: </tr>
501: <tr><td> </td></tr>
502: <tr>
1.28 raeburn 503: <td>).
504: &Apache::loncommon::start_data_table()."\n".
505: &Apache::loncommon::start_data_table_header_row()."\n".
506: "<th>$lt{'ownr'}</th>\n".
507: "<th>$lt{'name'}</th>\n".
508: "<th>$lt{'unme'}</th>\n".
509: "<th>$lt{'stus'}</th>\n".
510: &Apache::loncommon::end_data_table_header_row()."\n";
511: foreach my $cc (@local_ccs) {
512: $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
513: if ($cc eq $enrollvar{'courseowner'}) {
514: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked" /></td>'."\n";
1.1 raeburn 515: } else {
1.28 raeburn 516: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" /></td>'."\n";
1.1 raeburn 517: }
1.28 raeburn 518: $ownertable .=
519: '<td>'.$pname{$cc}.'</td>'."\n".
520: '<td>'.$cc.'</td>'."\n".
521: '<td>'.$cc_status{$cc}.' '.$lt{'ccor'}.'</td>'."\n".
522: &Apache::loncommon::end_data_table_row()."\n";
523: }
524: $ownertable .= &Apache::loncommon::end_data_table()."
1.1 raeburn 525: </td>
526: </tr>
527: </table>";
528: }
1.28 raeburn 529: &print_header($r,$cdesc,$javascript_validations);
530: my $type = $env{'form.type'};
1.29 raeburn 531: if ($type eq '') {
532: $type = 'Course';
533: }
1.28 raeburn 534: my $dctitle = &Apache::lonnet::plaintext('dc');
535: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
536: my $mainheader = &mt('Course settings modifiable by [_1] only.',$dctitle);
537: my $hidden_elements = &hidden_form_elements();
1.1 raeburn 538: $r->print(<<ENDDOCUMENT);
1.35 raeburn 539: <form action="/adm/modifycourse" method="post" name="$env{'form.phase'}">
1.28 raeburn 540: <h3>$mainheader</h3>
1.1 raeburn 541: </p><p>
1.2 raeburn 542: <table width="100%" cellspacing="6" cellpadding="6">
543: <tr>
1.32 raeburn 544: <td colspan="2">Use the appropriate text boxes and radio buttons below to change some or all of the four automated enrollment settings that may only be changed by a Domain Coordinator.
1.2 raeburn 545: </tr>
1.1 raeburn 546: <tr>
547: <td width="50%" valign="top">
1.2 raeburn 548: <b>$lt{'ccod'}:</b>
1.1 raeburn 549: <input type="text" size="10" name="coursecode" value="$enrollvar{'coursecode'}"/><br/><br/>
550: $lt{'ccus'}
551: </td>
552: <td width="50%" valign="top" rowspan="2">
1.2 raeburn 553: <b>$lt{'cown'}:</b><br/><br/>
554: $ownertable
555: <br/><br/>
1.1 raeburn 556: $lt{'cous'}
557: </td>
558: </tr>
559: <tr>
560: <td width="50%" valign="top">
1.2 raeburn 561: <b>$lt{'deam'}:</b><br/><br/>
1.32 raeburn 562: $authenitems
1.2 raeburn 563: <br/>
1.1 raeburn 564: $lt{'deus'}.
565: </td>
566: <td width="50%"> </td>
567: </tr>
568: </table>
569: <table width="90%" cellpadding="5" cellspacing="0">
570: <tr>
1.28 raeburn 571: <td align="left">
572: $hidden_elements
573: <input type="button" onClick="javascript:changePage(this.form,'processparms');javascript:verify_message(this.form)" value="$lt{'gobt'}" />
1.1 raeburn 574: </td>
575: </tr>
576: </table>
577: </form>
578: <br/>
579: <br/>
580: ENDDOCUMENT
1.5 raeburn 581: return;
1.1 raeburn 582: }
583:
584: sub modify_course {
1.30 raeburn 585: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1.28 raeburn 586: my %longtype = &course_settings_descrip();
587: my %settings = &Apache::lonnet::get('environment',['internal.courseowner','internal.coursecode','internal.authtype','internal.autharg','internal.sectionnums','internal.crosslistings','description'],$cdom,$cnum);
1.1 raeburn 588: my %currattr = ();
589: my %newattr = ();
590: my %cenv = ();
591: my $response;
592: my $chgresponse;
593: my $nochgresponse;
594: my $warning;
595: my $reply;
596: my @changes = ();
597: my @nochanges = ();
598: my @sections = ();
599: my @xlists = ();
1.38 raeburn 600: my %changed = ( code => 0,
601: owner => 0,
602: );
1.28 raeburn 603: unless ($settings{'internal.sectionnums'} eq '') {
1.1 raeburn 604: if ($settings{'internal.sectionnums'} =~ m/,/) {
605: @sections = split/,/,$settings{'internal.sectionnums'};
606: } else {
607: $sections[0] = $settings{'internal.sectionnums'};
608: }
609: }
610: unless ($settings{'internal.crosslistings'} eq'') {
611: if ($settings{'internal.crosslistings'} =~ m/,/) {
612: @xlists = split/,/,$settings{'internal.crosslistings'};
613: } else {
614: $xlists[0] = $settings{'internal.crosslistings'};
615: }
616: }
617:
1.28 raeburn 618: my @modifiable_params = &get_dc_settable();
619: foreach my $param (@modifiable_params) {
620: my $attr = 'internal.'.$param;
621: $currattr{$param} = $settings{$attr};
1.1 raeburn 622: }
623:
624: my $description = $settings{'description'};
625:
1.16 albertel 626: if ($env{'form.login'} eq 'krb') {
627: $newattr{'authtype'} = $env{'form.login'};
628: $newattr{'authtype'} .= $env{'form.krbver'};
629: $newattr{'autharg'} = $env{'form.krbarg'};
630: } elsif ($env{'form.login'} eq 'int') {
1.1 raeburn 631: $newattr{'authtype'} ='internal';
1.16 albertel 632: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
633: $newattr{'autharg'} = $env{'form.intarg'};
1.1 raeburn 634: }
1.16 albertel 635: } elsif ($env{'form.login'} eq 'loc') {
1.1 raeburn 636: $newattr{'authtype'} = 'localauth';
1.16 albertel 637: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
638: $newattr{'autharg'} = $env{'form.locarg'};
1.1 raeburn 639: }
640: }
641: if ( $newattr{'authtype'}=~ /^krb/) {
642: if ($newattr{'autharg'} eq '') {
1.45 ! bisitz 643: $warning = '<p class="LC_warning">'
! 644: .&mt('As you did not include the default Kerberos domain'
! 645: .' to be used for authentication in this class, the'
! 646: .' institutional data used by the automated'
! 647: .' enrollment process must include the Kerberos'
! 648: .' domain for each new student.')
! 649: .'</p>';
1.1 raeburn 650: }
651: }
652:
1.16 albertel 653: if ( exists($env{'form.courseowner'}) ) {
654: $newattr{'courseowner'}=$env{'form.courseowner'};
1.14 raeburn 655: unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
1.38 raeburn 656: $changed{'owner'} = 1;
1.1 raeburn 657: }
658: }
659:
1.16 albertel 660: if ( exists($env{'form.coursecode'}) ) {
661: $newattr{'coursecode'}=$env{'form.coursecode'};
1.1 raeburn 662: unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
1.38 raeburn 663: $changed{'code'} = 1;
1.1 raeburn 664: }
665: }
1.38 raeburn 666: if ($changed{'owner'} || $changed{'code'}) {
667: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',$cnum,
668: undef,undef,'.');
669: if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
670: $crsinfo{$env{'form.pickedcourse'}}{'inst_code'} = $env{'form.coursecode'};
671: $crsinfo{$env{'form.pickedcourse'}}{'owner'} = $env{'form.courseowner'};
672: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
673: my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
674: }
1.14 raeburn 675: }
1.28 raeburn 676: foreach my $param (@modifiable_params) {
677: if ($currattr{$param} eq $newattr{$param}) {
678: push(@nochanges,$param);
1.1 raeburn 679: } else {
1.28 raeburn 680: my $attr = 'internal.'.$param;
681: $cenv{$attr} = $newattr{$param};
682: push(@changes,$param);
1.1 raeburn 683: }
684: }
685: if (@changes > 0) {
1.2 raeburn 686: $chgresponse = &mt("The following automated enrollment parameters have been changed:<br/><ul>");
1.1 raeburn 687: }
688: if (@nochanges > 0) {
1.2 raeburn 689: $nochgresponse = &mt("The following automated enrollment parameters remain unchanged:<br/><ul>");
1.1 raeburn 690: }
1.33 raeburn 691: if (@changes > 0) {
1.28 raeburn 692: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1.1 raeburn 693: if ($putreply !~ /^ok$/) {
1.33 raeburn 694: $response = &mt("There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>").&mt('Error: ').$putreply;
1.1 raeburn 695: } else {
1.28 raeburn 696: foreach my $attr (@modifiable_params) {
1.1 raeburn 697: if (grep/^$attr$/,@changes) {
1.28 raeburn 698: $chgresponse .= "<li>$longtype{$attr} ".&mt("now set to \"").$newattr{$attr}."\".</li>";
1.1 raeburn 699: } else {
1.28 raeburn 700: $nochgresponse .= "<li>$longtype{$attr} ".&mt("still set to \"").$currattr{$attr}."\".</li>";
1.1 raeburn 701: }
702: }
1.38 raeburn 703: if ($changed{'code'} || $changed{'owner'}) {
1.1 raeburn 704: if ( $newattr{'courseowner'} eq '') {
1.2 raeburn 705: $warning .= &mt("There is no owner associated with this LON-CAPA course. If automated enrollment in LON-CAPA courses at your institution requires validation of course owners, automated enrollment will fail for this course.<br/>");
1.1 raeburn 706: } else {
707: if (@sections > 0) {
1.38 raeburn 708: if ($changed{'code'}) {
1.2 raeburn 709: foreach my $sec (@sections) {
710: if ($sec =~ m/^(.+):/) {
1.8 raeburn 711: my $inst_course_id = $newattr{'coursecode'}.$1;
1.28 raeburn 712: my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
1.7 raeburn 713: if ($course_check eq 'ok') {
1.28 raeburn 714: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
1.1 raeburn 715: unless ($outcome eq 'ok') {
1.2 raeburn 716: $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $1 for the following reason: $outcome.<br/>");
1.1 raeburn 717: }
718: } else {
1.2 raeburn 719: $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $1 for the following reason: $course_check.<br/>");
1.1 raeburn 720: }
721: } else {
1.2 raeburn 722: $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $sec because this is not a valid section entry.<br/>");
1.1 raeburn 723: }
724: }
1.38 raeburn 725: } elsif ($changed{'owner'}) {
1.4 raeburn 726: foreach my $sec (@sections) {
727: if ($sec =~ m/^(.+):/) {
1.8 raeburn 728: my $inst_course_id = $newattr{'coursecode'}.$1;
1.28 raeburn 729: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
1.4 raeburn 730: unless ($outcome eq 'ok') {
731: $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $1 for the following reason: $outcome.<br/>");
732: }
733: } else {
734: $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for ").$newattr{'coursecode'}.&mt(" - section $sec because this is not a valid section entry.<br/>");
735: }
736: }
737: }
1.1 raeburn 738: } else {
1.2 raeburn 739: $warning .= &mt("As no section numbers are currently listed for LON-CAPA course: ").$description.&mt(", automated enrollment will not occur for any sections of coursecode: ").$newattr{'coursecode'}."<br/>";
1.1 raeburn 740: }
1.38 raeburn 741: if ( (@xlists > 0) && ($changed{'owner'}) ) {
1.1 raeburn 742: foreach my $xlist (@xlists) {
743: if ($xlist =~ m/^(.+):/) {
1.28 raeburn 744: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$1,$newattr{'courseowner'});
1.1 raeburn 745: unless ($outcome eq 'ok') {
1.2 raeburn 746: $warning .= &mt("If automatic enrollment is enabled for LON-CAPA course: ").$description.&mt(", automated enrollment may fail for crosslisted class: ").$1.&mt(" for the following reason: $outcome.<br/>");
1.1 raeburn 747: }
1.28 raeburn 748: }
1.1 raeburn 749: }
750: }
751: }
752: }
753: }
1.2 raeburn 754: } else {
1.28 raeburn 755: foreach my $attr (@modifiable_params) {
756: $nochgresponse .= "<li>$longtype{$attr} ".&mt("still set to")." \"".$currattr{$attr}."\".</li>";
1.2 raeburn 757: }
1.1 raeburn 758: }
759:
760: if (@changes > 0) {
761: $chgresponse .= "</ul><br/><br/>";
762: }
763: if (@nochanges > 0) {
764: $nochgresponse .= "</ul><br/><br/>";
765: }
766: unless ($warning eq '') {
1.2 raeburn 767: $warning = &mt("The following warning messages were generated as a result of applying the changes you specified to course settings that can affect the automated enrollment process:<br/><br/>").$warning;
1.1 raeburn 768: }
769: if ($response eq '') {
770: $reply = $chgresponse.$nochgresponse.$warning;
771: } else {
772: $reply = $response;
773: }
1.28 raeburn 774: &print_header($r,$cdesc);
775: $reply = '<h3>'.
776: &mt('Result of Changes to Automated Enrollment Settings.').
777: '</h3>'."\n".
778: '<table><tr><td>'.$reply.'</td></tr></table>'.
779: '<form action="/adm/modifycourse" method="post" name="processparms">'.
780: &hidden_form_elements().
781: '<a href="javascript:changePage(document.processparms,'."'menu'".')">'.&mt('Back to options page').'</a>
782: </form>';
1.3 raeburn 783: $r->print($reply);
1.28 raeburn 784: return;
785: }
786:
787: sub modify_quota {
788: my ($r,$cdom,$cnum,$cdesc,$domdesc) = @_;
789: &print_header($r,$cdesc);
790:
791: my %lt = &Apache::lonlocal::texthash(
792: 'back' => 'Back to options page',
793: );
794: $r->print('
795: <form action="/adm/modifycourse" method="post" name="processquota">
1.43 weissno 796: <h3>'.&mt('Disk space for storage of group portfolio for [_1]',$cdesc).
1.28 raeburn 797: '</h3>');
798: my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
799: my $defaultquota = 20;
800: if ($env{'form.coursequota'} ne '') {
801: my $newquota = $env{'form.coursequota'};
802: if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
803: $newquota = $1;
804: if ($oldsettings{'internal.coursequota'} eq $env{'form.coursequota'}) {
1.43 weissno 805: $r->print(&mt('The disk space allocated for group portfolio remains unchanged as ').$env{'form.coursequota'}.' Mb');
1.28 raeburn 806: } else {
807: my %cenv = (
808: 'internal.coursequota' => $env{'form.coursequota'},
809: );
810: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
811: $cnum);
812: if (($oldsettings{'internal.coursequota'} eq '') &&
813: ($env{'form.coursequota'} == $defaultquota)) {
1.43 weissno 814: $r->print(&mt('The disk space allocated for group portfolio in this course is the default quota for this domain:').' '.$defaultquota.' Mb');
1.28 raeburn 815: } else {
816: if ($putreply eq 'ok') {
817: my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
1.43 weissno 818: $r->print(&mt('The disk space allocated for group portfolio is now:').' '.$updatedsettings{'internal.coursequota'}.' Mb.');
1.28 raeburn 819: my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
820: if ($usage >= $updatedsettings{'internal.coursequota'}) {
821: my $newoverquota;
822: if ($usage < $oldsettings{'internal.coursequota'}) {
823: $newoverquota = 'now';
824: }
825: $r->print('<br /><br />'.
826: &mt('Disk usage [_1] exceeds the quota for this course.',$newoverquota).' '.
827: &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.'));
828: }
829: } else {
830: $r->print(&mt('There was an error'));
831: }
832: }
833: }
834: } else {
835: $r->print(&mt('The new quota requested contained invalid characters, so the quota is unchanged.'));
836: }
837: }
838: $r->print(qq|<br /><br />
839: <a href="javascript:changePage(document.processquota,'menu')">$lt{'back'}</a>|);
840: $r->print(&hidden_form_elements().'</form>');
841: return;
1.1 raeburn 842: }
843:
1.38 raeburn 844: sub modify_catsettings {
845: my ($r,$cdom,$cnum,$cdesc,$domdesc) = @_;
846: &print_header($r,$cdesc);
847: my %lt = &Apache::lonlocal::texthash(
848: 'back' => 'Back to options page',
849: );
850: my %desc = &Apache::lonlocal::texthash(
851: 'hidefromcat' => 'Excluded from course catalog',
852: 'categories' => 'Assigned categories for this course',
853: );
854: $r->print('
855: <form action="/adm/modifycourse" method="post" name="processcat">
856: <h3>'.&mt('Category settings').'</h3>');
857: my %domconf = &Apache::lonnet::get_dom('configuration',['coursecategories'],$cdom);
858: my @cat_params = &catalog_settable($domconf{'coursecategories'});
859: if (@cat_params > 0) {
860: my (%cenv,@changes,@nochanges);
861: my %currsettings =
862: &Apache::lonnet::get('environment',['hidefromcat','categories'],$cdom,$cnum);
863: my (@newcategories,%showitem);
864: if (grep(/^togglecats$/,@cat_params)) {
865: if ($currsettings{'hidefromcat'} ne $env{'form.hidefromcat'}) {
866: push(@changes,'hidefromcat');
867: $cenv{'hidefromcat'} = $env{'form.hidefromcat'};
868: } else {
869: push(@nochanges,'hidefromcat');
870: }
871: if ($env{'form.hidefromcat'} eq 'yes') {
872: $showitem{'hidefromcat'} = '"'.&mt('Yes')."'";
873: } else {
874: $showitem{'hidefromcat'} = '"'.&mt('No').'"';
875: }
876: }
877: if (grep(/^categorize$/,@cat_params)) {
878: my (@cats,@trails,%allitems,%idx,@jsarray);
879: if (ref($domconf{'coursecategories'}) eq 'HASH') {
880: my $cathash = $domconf{'coursecategories'}{'cats'};
881: if (ref($cathash) eq 'HASH') {
882: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
883: \%allitems,\%idx,\@jsarray);
884: }
885: }
886: @newcategories = &Apache::loncommon::get_env_multiple('form.usecategory');
887: if (@newcategories == 0) {
888: $showitem{'categories'} = '"'.&mt('None').'"';
889: } else {
890: $showitem{'categories'} = '<ul>';
891: foreach my $item (@newcategories) {
892: $showitem{'categories'} .= '<li>'.$trails[$allitems{$item}].'</li>';
893: }
894: $showitem{'categories'} .= '</ul>';
895: }
896: my $catchg = 0;
897: if ($currsettings{'categories'} ne '') {
898: my @currcategories = split('&',$currsettings{'categories'});
899: foreach my $cat (@currcategories) {
900: if (!grep(/^\Q$cat\E$/,@newcategories)) {
901: $catchg = 1;
902: last;
903: }
904: }
905: if (!$catchg) {
906: foreach my $cat (@newcategories) {
907: if (!grep(/^\Q$cat\E$/,@currcategories)) {
908: $catchg = 1;
909: last;
910: }
911: }
912: }
913: } else {
914: if (@newcategories > 0) {
915: $catchg = 1;
916: }
917: }
918: if ($catchg) {
919: $cenv{'categories'} = join('&',@newcategories);
920: push(@changes,'categories');
921: } else {
922: push(@nochanges,'categories');
923: }
924: if (@changes > 0) {
925: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
926: if ($putreply eq 'ok') {
927: my %crsinfo = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
928: $cnum,undef,undef,'.');
929: if (ref($crsinfo{$env{'form.pickedcourse'}}) eq 'HASH') {
930: if (grep(/^hidefromcat$/,@changes)) {
931: $crsinfo{$env{'form.pickedcourse'}}{'hidefromcat'} = $env{'form.hidefromcat'};
932: }
933: if (grep(/^categories$/,@changes)) {
934: $crsinfo{$env{'form.pickedcourse'}}{'categories'} = $cenv{'categories'};
935: }
936: my $chome = &Apache::lonnet::homeserver($cnum,$cdom);
937: my $putres = &Apache::lonnet::courseidput($cdom,\%crsinfo,$chome,'notime');
938: }
939: $r->print(&mt('The following changes occurred').'<ul>');
940: foreach my $item (@changes) {
941: $r->print('<li>'.&mt('[_1] now set to [_2]',$desc{$item},$showitem{$item}).'</li>');
942: }
943: $r->print('</ul><br />');
944: }
945: }
946: if (@nochanges > 0) {
947: $r->print(&mt('The following were unchanged').'<ul>');
948: foreach my $item (@nochanges) {
949: $r->print('<li>'.&mt('[_1] still set to [_2]',$desc{$item},$showitem{$item}).'</li>');
950: }
951: $r->print('</ul>');
952: }
953: }
954: } else {
955: $r->print(&mt('Category settings for courses in this domain should be modified in course context (via "Set Course Environment").').'<br />');
956: }
957: $r->print('<br />'."\n".
958: '<a href="javascript:changePage(document.processcat,'."'menu'".')">'.
959: $lt{'back'}.'</a>');
960: $r->print(&hidden_form_elements().'</form>');
961: return;
962: }
963:
1.1 raeburn 964: sub print_header {
1.28 raeburn 965: my ($r,$cdesc,$javascript_validations) = @_;
966: my $phase = "start";
967: if ( exists($env{'form.phase'}) ) {
968: $phase = $env{'form.phase'};
969: }
970: my $js = qq|
971: <script type="text/javascript">
972: function changePage(formname,newphase) {
973: formname.phase.value = newphase;
974: if (newphase == 'processparms') {
975: return;
1.1 raeburn 976: }
1.28 raeburn 977: formname.submit();
978: }
979: </script>
980: |;
981: if ($phase eq 'setparms') {
982: $js .= qq|
983: <script type="text/javascript">
984: $javascript_validations
985: </script>
986: |;
987: } elsif ($phase eq 'courselist') {
988: $js .= qq|
989: <script type="text/javascript">
990: function gochoose(cname,cdom,cdesc) {
991: document.courselist.pickedcourse.value = cdom+'_'+cname;
992: document.courselist.submit();
993: }
994: </script>
995: |;
996: } elsif ($phase eq 'setquota') {
997: $js .= <<'ENDSCRIPT';
998: <script type="text/javascript">
999: function verify_quota(formname) {
1000: var newquota = formname.coursequota.value;
1001: var num_reg = /^\s*(\d+\.?\d*|\.\d+)\s*$/;
1002: if (num_reg.test(newquota)) {
1003: changePage(formname,'processquota');
1.1 raeburn 1004: } else {
1.28 raeburn 1005: alert("The quota you entered contained invalid characters.\nYou must enter a number");
1.1 raeburn 1006: }
1.28 raeburn 1007: return;
1008: }
1009: </script>
1010: ENDSCRIPT
1.1 raeburn 1011: }
1.37 raeburn 1012: my $starthash;
1013: if ($env{'form.phase'} eq 'ccrole') {
1014: $starthash = {
1015: add_entries => {'onload' => "javascript:document.ccrole.submit();"},
1016: };
1017: }
1.23 albertel 1018: $r->print(&Apache::loncommon::start_page('View/Modify Course Settings',
1.37 raeburn 1019: $js,$starthash));
1.28 raeburn 1020: my $bread_text = "View/Modify Courses";
1021: if ($cdesc ne '') {
1.41 raeburn 1022: $bread_text = &mt('Course Settings: [_1]',$cdesc);
1023: my $no_mt = 1;
1024: $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text,undef,undef,
1025: undef,undef,$no_mt));
1026: } else {
1027: $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
1028: }
1.5 raeburn 1029: return;
1.1 raeburn 1030: }
1031:
1032: sub print_footer {
1.23 albertel 1033: my ($r) = @_;
1034: $r->print('<br />'.&Apache::loncommon::end_page());
1.5 raeburn 1035: return;
1.3 raeburn 1036: }
1037:
1038: sub check_course {
1.28 raeburn 1039: my ($r,$dom,$domdesc) = @_;
1040: my ($ok_course,$description,$instcode,$owner);
1.35 raeburn 1041: my %args = (
1042: one_time => 1,
1043: );
1044: my %coursehash =
1045: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},\%args);
1046: my $cnum = $coursehash{'num'};
1047: my $cdom = $coursehash{'domain'};
1048: if ($cdom eq $dom) {
1049: my $description;
1050: my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
1.38 raeburn 1051: $cnum,undef,undef,'.');
1.35 raeburn 1052: if (keys(%courseIDs) > 0) {
1053: $ok_course = 'ok';
1054: my ($instcode,$owner);
1055: if (ref($courseIDs{$cdom.'_'.$cnum}) eq 'HASH') {
1056: $description = $courseIDs{$cdom.'_'.$cnum}{'description'};
1057: $instcode = $courseIDs{$cdom.'_'.$cnum}{'inst_code'};
1058: $owner = $courseIDs{$cdom.'_'.$cnum}{'owner'};
1059: } else {
1060: ($description,$instcode,$owner) =
1061: split(/:/,$courseIDs{$cdom.'_'.$cnum});
1062: }
1063: $description = &unescape($description);
1064: $instcode = &unescape($instcode);
1065: if ($instcode) {
1066: $description .= " ($instcode)";
1.5 raeburn 1067: }
1.35 raeburn 1068: return ($ok_course,$description);
1.3 raeburn 1069: }
1070: }
1.1 raeburn 1071: }
1072:
1.28 raeburn 1073: sub course_settings_descrip {
1074: my %longtype = &Apache::lonlocal::texthash(
1075: 'authtype' => 'Default authentication method',
1076: 'autharg' => 'Default authentication parameter',
1077: 'autoadds' => 'Automated adds',
1078: 'autodrops' => 'Automated drops',
1079: 'autostart' => 'Date of first automated enrollment',
1080: 'autoend' => 'Date of last automated enrollment',
1081: 'default_enrollment_start_date' => 'Date of first student access',
1082: 'default_enrollment_end_date' => 'Date of last student access',
1083: 'coursecode' => 'Official course code',
1084: 'courseowner' => "Username:domain of course owner",
1085: 'notifylist' => 'Course Coordinators to be notified of enrollment changes',
1086: 'sectionnums' => 'Course section number(:LON-CAPA section)',
1087: 'crosslistings' => 'Crosslisted class(:LON-CAPA section)',
1088: );
1089: return %longtype;
1090: }
1091:
1092: sub hidden_form_elements {
1093: my $hidden_elements =
1094: &Apache::lonhtmlcommon::echo_form_input(['gosearch','coursecode',
1.37 raeburn 1095: 'prevphase','numlocalcc','courseowner','login','coursequota','intarg',
1.38 raeburn 1096: 'locarg','krbarg','krbver','counter','hidefromcat','usecategory'])."\n".
1.37 raeburn 1097: '<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />';
1.28 raeburn 1098: return $hidden_elements;
1099: }
1.1 raeburn 1100:
1101: sub handler {
1102: my $r = shift;
1103: if ($r->header_only) {
1104: &Apache::loncommon::content_type($r,'text/html');
1105: $r->send_http_header;
1106: return OK;
1107: }
1.28 raeburn 1108: my $dom = $env{'request.role.domain'};
1.31 albertel 1109: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.28 raeburn 1110: if (&Apache::lonnet::allowed('ccc',$dom)) {
1.1 raeburn 1111: &Apache::loncommon::content_type($r,'text/html');
1112: $r->send_http_header;
1113:
1.28 raeburn 1114: &Apache::lonhtmlcommon::clear_breadcrumbs();
1115:
1116: my $phase = $env{'form.phase'};
1.37 raeburn 1117: if ($phase eq '') {
1118: &Apache::lonhtmlcommon::add_breadcrumb
1.28 raeburn 1119: ({href=>"/adm/modifycourse",
1120: text=>"Course search"});
1121: &print_course_search_page($r,$dom,$domdesc);
1.1 raeburn 1122: } else {
1.37 raeburn 1123: my $firstform = $phase;
1124: if ($phase eq 'courselist') {
1125: $firstform = 'filterpicker';
1126: }
1.28 raeburn 1127: &Apache::lonhtmlcommon::add_breadcrumb
1.37 raeburn 1128: ({href=>"javascript:changePage(document.$firstform,'')",
1129: text=>"Course search"},
1130: {href=>"javascript:changePage(document.$phase,'courselist')",
1.28 raeburn 1131: text=>"Choose a course"});
1132: if ($phase eq 'courselist') {
1133: &print_course_selection_page($r,$dom,$domdesc);
1134: } else {
1135: my ($checked,$cdesc) = &check_course($r,$dom,$domdesc);
1136: my $type = $env{'form.type'};
1.29 raeburn 1137: if ($type eq '') {
1138: $type = 'Course';
1139: }
1.28 raeburn 1140: if ($checked eq 'ok') {
1141: if ($phase eq 'menu') {
1.37 raeburn 1142: &Apache::lonhtmlcommon::add_breadcrumb
1143: ({href=>"javascript:changePage(document.$phase,'menu')",
1144: text=>"Pick action"});
1.38 raeburn 1145: &print_modification_menu($r,$cdesc,$domdesc,$dom);
1.37 raeburn 1146: } elsif ($phase eq 'ccrole') {
1147: &Apache::lonhtmlcommon::add_breadcrumb
1148: ({href=>"javascript:changePage(document.$phase,'ccrole')",
1149: text=>"Enter course"});
1150: &print_ccrole_selected($r,$cdesc,$domdesc);
1.28 raeburn 1151: } else {
1.37 raeburn 1152: &Apache::lonhtmlcommon::add_breadcrumb
1153: ({href=>"javascript:changePage(document.$phase,'menu')",
1154: text=>"Pick action"});
1.28 raeburn 1155: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
1156: if ($phase eq 'setquota') {
1157: &Apache::lonhtmlcommon::add_breadcrumb
1158: ({href=>"javascript:changePage(document.$phase,'$phase')",
1159: text=>"Set quota"});
1.38 raeburn 1160: &print_setquota($r,$cdom,$cnum,$cdesc,$type);
1.28 raeburn 1161: } elsif ($phase eq 'processquota') {
1162: &Apache::lonhtmlcommon::add_breadcrumb
1163: ({href=>"javascript:changePage(document.$phase,'setquota')",
1164: text=>"Set quota"});
1165: &Apache::lonhtmlcommon::add_breadcrumb
1166: ({href=>"javascript:changePage(document.$phase,'$phase')",
1167: text=>"Result"});
1168: &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc);
1169: } elsif ($phase eq 'viewparms') {
1170: &Apache::lonhtmlcommon::add_breadcrumb
1171: ({href=>"javascript:changePage(document.$phase,'viewparms')",
1172: text=>"Display settings"});
1173: &print_settings_display($r,$cdom,$cnum,$cdesc,$type);
1174: } elsif ($phase eq 'setparms') {
1175: &Apache::lonhtmlcommon::add_breadcrumb
1176: ({href=>"javascript:changePage(document.$phase,'$phase')",
1177: text=>"Change settings"});
1178: &print_course_modification_page($r,$cdom,$cnum,$cdesc,$domdesc);
1179: } elsif ($phase eq 'processparms') {
1180: &Apache::lonhtmlcommon::add_breadcrumb
1181: ({href=>"javascript:changePage(document.$phase,'setparms')",
1182: text=>"Change settings"});
1183: &Apache::lonhtmlcommon::add_breadcrumb
1184: ({href=>"javascript:changePage(document.$phase,'$phase')",
1185: text=>"Result"});
1.30 raeburn 1186: &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.38 raeburn 1187: } elsif ($phase eq 'catsettings') {
1188: &Apache::lonhtmlcommon::add_breadcrumb
1189: ({href=>"javascript:changePage(document.$phase,'$phase')",
1190: text=>"Catalog settings"});
1191: &print_catsettings($r,$cdom,$cnum,$cdesc,$type);
1192: } elsif ($phase eq 'processcat') {
1193: &Apache::lonhtmlcommon::add_breadcrumb
1194: ({href=>"javascript:changePage(document.$phase,'catsettings')",
1195: text=>"Catalog settings"});
1196: &Apache::lonhtmlcommon::add_breadcrumb
1197: ({href=>"javascript:changePage(document.$phase,'$phase')",
1198: text=>"Result"});
1199: &modify_catsettings($r,$cdom,$cnum,$cdesc,$domdesc);
1.28 raeburn 1200: }
1201: }
1202: } else {
1.33 raeburn 1203: $r->print('<span class="LC_error">'.&mt('The course you selected is not a valid course in this domain')." ($domdesc)".'</span>');
1.28 raeburn 1204: }
1205: }
1.1 raeburn 1206: }
1.28 raeburn 1207: &print_footer($r);
1.1 raeburn 1208: } else {
1.16 albertel 1209: $env{'user.error.msg'}=
1.2 raeburn 1210: "/adm/modifycourse:ccc:0:0:Cannot modify course settings";
1.1 raeburn 1211: return HTTP_NOT_ACCEPTABLE;
1212: }
1213: return OK;
1214: }
1215:
1216: 1;
1217: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>