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