Annotation of loncom/interface/lonmodifycourse.pm, revision 1.30
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.30 ! raeburn 4: # $Id: lonmodifycourse.pm,v 1.29 2006/12/29 17:30:11 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;
36: use Apache::londropadd;
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:
46: sub get_enrollment_settings {
47: my ($cdom,$cnum) = @_;
48: my %settings = &Apache::lonnet::dump('environment',$cdom,$cnum);
49: my %enrollvar;
50: $enrollvar{'autharg'} = '';
51: $enrollvar{'authtype'} = '';
1.1 raeburn 52: my %lt=&Apache::lonlocal::texthash(
1.28 raeburn 53: 'noen' => "No end date",
1.1 raeburn 54: );
1.28 raeburn 55: foreach my $item (keys %settings) {
56: if ($item =~ m/^internal\.(.+)$/) {
57: my $type = $1;
58: if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
59: if ($settings{$item} == 1) {
60: $enrollvar{$type} = "ON";
61: } else {
62: $enrollvar{$type} = "OFF";
1.10 raeburn 63: }
1.28 raeburn 64: } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
65: if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
66: $enrollvar{$type} = $lt{'noen'};
67: } else {
68: $enrollvar{$type} = localtime($settings{$item});
1.14 raeburn 69: }
1.30 ! raeburn 70: } elsif ($type eq "sectionnums") {
1.28 raeburn 71: $enrollvar{$type} = $settings{$item};
72: $enrollvar{$type} =~ s/,/, /g;
73: } elsif ($type eq "authtype"
74: || $type eq "autharg" || $type eq "coursecode"
75: || $type eq "crosslistings") {
76: $enrollvar{$type} = $settings{$item};
77: } elsif ($type eq 'courseowner') {
78: if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
79: $enrollvar{$type} = $settings{$item};
80: } else {
81: if ($settings{$item} ne '') {
82: $enrollvar{$type} = $settings{$item}.':'.$cdom;
1.26 raeburn 83: }
1.1 raeburn 84: }
1.28 raeburn 85: }
86: } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
87: my $type = $1;
88: if ( ($type eq 'end') && ($settings{$item} == 0) ) {
89: $enrollvar{$item} = $lt{'noen'};
90: } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
91: $enrollvar{$item} = 'When enrolled';
92: } else {
93: $enrollvar{$item} = localtime($settings{$item});
1.1 raeburn 94: }
95: }
96: }
1.28 raeburn 97: return %enrollvar;
98: }
99:
100: sub print_course_search_page {
101: my ($r,$dom,$domdesc) = @_;
102: &print_header($r);
103: my $filterlist = ['descriptfilter',
104: 'instcodefilter','ownerfilter',
105: 'ownerdomfilter','coursefilter'];
106: my $filter = {};
107: my $type = 'Course';
108: my $action = '/adm/modifycourse';
109: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
110: my $dctitle = &Apache::lonnet::plaintext('dc');
111: my %lt=&Apache::lonlocal::texthash(
112: 'some' => "Certain settings which control auto-enrollment of students from your institution's student information system.",
113: 'crqo' => 'The total disk space allocated for storage of portfolio files in all groups in a course.',
114: 'tmod' => 'To view or modify these settings use the criteria below to select a course from this domain.',
115: );
116: $r->print('<h3>'.
117: &mt('Course settings which only a [_1] may modify.'
118: ,$dctitle).'</h3>'.
119: &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).'
120: <ul>
121: <li>'.$lt{'some'}.'</li>
122: <li>'.$lt{'crqo'}.'</li>
123: </ul>'.
124: $lt{'tmod'}.' ('.$domdesc.')
125: <br /><br />
126: ');
127: $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
128: undef,undef,$filter,$action,'modifycourse'));
129: }
130:
131: sub print_course_selection_page {
132: my ($r,$dom,$domdesc) = @_;
133: &print_header($r);
134:
135: # Criteria for course search
136: my $filterlist = ['descriptfilter',
137: 'instcodefilter','ownerfilter',
138: 'ownerdomfilter','coursefilter'];
139: my %filter;
140: my $type = $env{'form.type'};
1.29 raeburn 141: if ($type eq '') {
142: $type = 'Course';
143: }
1.28 raeburn 144: my $action = '/adm/modifycourse';
145: my $dctitle = &Apache::lonnet::plaintext('dc');
146: $r->print(&mt('Revise your search criteria for this domain').' ('.$domdesc.').<br /><br />');
147: $r->print(&Apache::lonpickcourse::build_filters($filterlist,$type,
148: undef,undef,\%filter,$action));
149: $filter{'domainfilter'} = $dom;
150: my %courses = &Apache::lonpickcourse::search_courses($r,$type,0,
151: \%filter);
152: if (keys(%courses) > 0) {
153: $r->print(&mt("Click a 'Select' button to view or modify settings for a [_1] which may only be modified by a [_2] in this domain.",lc($type),$dctitle).'<br /><br />');
154: }
155:
156: &Apache::lonpickcourse::display_matched_courses($r,$type,0,$action,
157: %courses);
1.1 raeburn 158: return;
159: }
160:
1.28 raeburn 161: sub print_modification_menu {
162: my ($r,$cdesc) = @_;
163: &print_header($r,$cdesc);
164: my @menu =
165: (
166: { text => 'Modify quota for group portfolio files',
167: phase => 'setquota',
168: },
169: { text => 'Display current settings for automated enrollment',
170: phase => 'viewparms',
171: },
172: { text => 'Modify institutional code, course owner and/or default authentication',
173: phase => 'setparms',
174: }
175: );
176: my $menu_html = '<h3>'.&mt('View/Modify settings for: ').$cdesc.'</h3>'."\n".
177: '<form name="menu" method="post" action="/adm/modifycourse" />'."\n".
178: &hidden_form_elements();
179: foreach my $menu_item (@menu) {
180: $menu_html.='<p>';
181: $menu_html.='<font size="+1">';
182: $menu_html.=
183: qq|<a href="javascript:changePage(document.menu,'$menu_item->{'phase'}')">|;
184: $menu_html.= &mt($menu_item->{'text'}).'</a></font>';
185: $menu_html.='</p>';
1.3 raeburn 186: }
1.28 raeburn 187:
188: $r->print($menu_html);
189: return;
190: }
191:
192: sub print_settings_display {
193: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
194: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
195: my %longtype = &course_settings_descrip();
196: my %lt = &Apache::lonlocal::texthash(
197: 'cset' => "Course setting",
198: 'valu' => "Current value",
199: 'caes' => 'Current automated enrollment settings for ',
200: 'cour' => "Course settings that control automated enrollment in this LON-CAPA course are currently:",
201: '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:",
202: 'dcon' => "Modifiable by DC only",
203: 'back' => "Back to options page",
204: );
205:
206: my @bgcolors = ('#eeeeee','#cccccc');
207: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
208: my $dctitle = &Apache::lonnet::plaintext('dc');
209: my @modifiable_params = &get_dc_settable();
210:
211: my $disp_table = &Apache::loncommon::start_data_table()."\n".
212: &Apache::loncommon::start_data_table_header_row()."\n".
213: "<th>$lt{'cset'}</th>\n".
214: "<th>$lt{'valu'}</th>\n".
215: "<th>$lt{'dcon'}</th>\n".
216: &Apache::loncommon::end_data_table_header_row()."\n";
217: foreach my $key (sort(keys(%enrollvar))) {
218: $disp_table .= &Apache::loncommon::start_data_table_row()."\n".
219: "<td>$longtype{$key}</td>\n".
220: "<td>$enrollvar{$key}</td>\n";
221: if (grep(/^\Q$key\E$/,@modifiable_params)) {
222: $disp_table .= '<td>'.&mt('Yes').'</td>'."\n";
223: } else {
224: $disp_table .= '<td>'.&mt('No').'</td>'."\n";
225: }
226: $disp_table .= &Apache::loncommon::end_data_table_row()."\n";
1.3 raeburn 227: }
1.28 raeburn 228: $disp_table .= &Apache::loncommon::end_data_table()."\n";
229: &print_header($r,$cdesc);
230: $r->print('
231: <h3>'.$lt{'caes'}.'</h3>
232: <p>
233: <form action="/adm/modifycourse" method="post" name="viewparms">
234: '.$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>
235: </p><p>
236: '.$lt{'cour'}.'
237: </p><p>
238: '.$disp_table.'
239: </p><p>
240: <a href="javascript:changePage(document.viewparms,'."'menu'".')">'.$lt{'back'}.'</a>
241: <a href="javascript:changePage(document.viewparms,'."'setparms'".')">'.&mt('Modify [_1]-only settings',$dctitle).'</a>'."\n".
242: &hidden_form_elements().
243: '</form>');
244: }
1.3 raeburn 245:
1.28 raeburn 246: sub print_setquota {
247: my ($r,$cdom,$cnum,$cdesc,$type) = @_;
248: my $dctitle = &Apache::lonnet::plaintext('dc');
249: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
250: 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);
251: my %lt = &Apache::lonlocal::texthash(
252: 'cquo' => 'Disk space for storage of group portfolio files',
253: 'gpqu' => 'Course portfolio files disk space',
254: 'each' => 'Each course group can be assigned a quota for portfolio files uploaded to the group.',
255: 'modi' => 'Modify quota',
256: 'back' => "Back to options page",
257: );
258: my %settings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
259: my $coursequota = $settings{'internal.coursequota'};
260: if ($coursequota eq '') {
261: $coursequota = 20;
1.3 raeburn 262: }
1.28 raeburn 263: &print_header($r,$cdesc);
264: my $hidden_elements = &hidden_form_elements();
265: $r->print(<<ENDDOCUMENT);
266: <form action="/adm/modifycourse" method="post" name="setquota">
267: <h3>$lt{'cquo'}.</h3>
268: <p>
269: $lt{'each'}<br />
270: $subdiv
271: </p><p>
272: $lt{'gpqu'}: <input type="text" size="4" name="coursequota" value="$coursequota" /> Mb
273: <input type="button" onClick="javascript:verify_quota(this.form)" value="$lt{'modi'}" />
274: </p>
275: $hidden_elements
276: <a href="javascript:changePage(document.setquota,'menu')">$lt{'back'}</a>
277: </form>
278: ENDDOCUMENT
279: return;
280: }
1.3 raeburn 281:
1.28 raeburn 282: sub print_course_modification_page {
283: my ($r,$cdom,$cnum,$cdesc,$domdesc) = @_;
284: my %longtype = &course_settings_descrip();
285: my %enrollvar = &get_enrollment_settings($cdom,$cnum);
1.1 raeburn 286: my $ownertable;
1.2 raeburn 287: my %lt=&Apache::lonlocal::texthash(
288: 'actv' => "Active",
289: 'inac' => "Inactive",
290: 'ccor' => "Course Coordinator",
291: 'noen' => "No end date",
292: 'ownr' => "Owner",
293: 'name' => "Name",
1.26 raeburn 294: 'unme' => "Username:Domain",
1.2 raeburn 295: 'stus' => "Status",
1.28 raeburn 296: 'cquo' => "Disk space for storage of group portfolio files",
297: 'gpqu' => "Course portfolio files disk space",
298: 'each' => "Each course group can be assigned a quota for portfolio files uploaded to the group.",
1.2 raeburn 299: '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 ",
300: 'aenm' => "Automated Enrollment Manager",
301: 'andb' => " and (b) settings that may only be modified by a Domain Coordinator via this page.",
302: 'caes' => 'Current automated enrollment settings',
303: 'cour' => "Course settings that control automated enrollment in this LON-CAPA course
304: are currently:",
305: '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.",
306: 'ccus' => "A course coordinator can use the 'Automated Enrollment Manager' to change
307: 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).",
308: 'ccod' => "Course Code",
309: '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.",
310: 'cown' => "Course Owner",
311: '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.",
312: 'tabl' => 'The table below contains a list of active course coordinators in this course, who are from this domain',
313: 'usrd' => 'Use the radio buttons to select a different course owner.',
314: 'deam' => "Default Authentication method",
315: '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.",
316: 'gobt' => "Modify settings",
317: );
1.28 raeburn 318: my @bgcolors = ('#eeeeee','#cccccc');
1.2 raeburn 319:
1.28 raeburn 320: my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$cdom,$cnum);
1.1 raeburn 321: my @local_ccs = ();
322: my %cc_status = ();
323: my %pname = ();
324: my $active_cc;
1.26 raeburn 325: foreach my $person (@coursepersonnel) {
326: my ($role,$user) = split(/:/,$person,2);
327: $user =~ s/:$//;
328: if (($role eq 'cc') && ($user ne '')) {
329: if (!grep(/^\Q$user\E$/,@local_ccs)) {
330: my ($ccname,$ccdom) = split(/:/,$user);
331: $active_cc =
1.28 raeburn 332: &Apache::loncommon::check_user_status($ccdom,$ccname,$cdom,
333: $cnum,'cc');
1.19 raeburn 334: if ($active_cc eq 'active') {
1.26 raeburn 335: push(@local_ccs,$user);
336: $pname{$user} = &Apache::loncommon::plainname($ccname,$ccdom);
337: $cc_status{$user} = $lt{'actv'};
1.1 raeburn 338: }
339: }
340: }
341: }
1.26 raeburn 342: if ( (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs)) &&
343: ($enrollvar{'courseowner'} ne '') ) {
344: my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
345: push(@local_ccs,$enrollvar{'courseowner'});
346: $pname{$enrollvar{'courseowner'}} =
347: &Apache::loncommon::plainname($owneruname,$ownerdom);
348: $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
1.28 raeburn 349: $cdom,$cnum,'cc');
1.19 raeburn 350: if ($active_cc eq 'active') {
1.2 raeburn 351: $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1 raeburn 352: } else {
1.2 raeburn 353: $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1 raeburn 354: }
355: }
356: my $numlocalcc = @local_ccs;
1.24 albertel 357:
1.2 raeburn 358: my $helplink=&Apache::loncommon::help_open_topic('Modify_Course',&mt("Help on Modifying Courses"));
1.28 raeburn 359: my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($cdom);
1.2 raeburn 360: my $curr_authtype = '';
361: my $curr_authfield = '';
362: if ($enrollvar{'authtype'} =~ /^krb/) {
363: $curr_authtype = 'krb';
364: } elsif ($enrollvar{'authtype'} eq 'internal' ) {
365: $curr_authtype = 'int';
366: } elsif ($enrollvar{'authtype'} eq 'localauth' ) {
367: $curr_authtype = 'loc';
368: }
369: unless ($curr_authtype eq '') {
370: $curr_authfield = $curr_authtype.'arg';
371: }
1.28 raeburn 372: my $javascript_validations=&Apache::londropadd::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield);
1.2 raeburn 373: my %param = ( formname => 'document.cmod',
1.1 raeburn 374: kerb_def_dom => $krbdefdom,
1.2 raeburn 375: kerb_def_auth => $krbdef,
376: mode => 'modifycourse',
377: curr_authtype => $curr_authtype,
378: curr_autharg => $enrollvar{'autharg'}
1.1 raeburn 379: );
380: my $krbform = &Apache::loncommon::authform_kerberos(%param);
381: my $intform = &Apache::loncommon::authform_internal(%param);
382: my $locform = &Apache::loncommon::authform_local(%param);
383:
384: if ($numlocalcc == 0) {
1.2 raeburn 385: $ownertable = $lt{'nocc'};
1.1 raeburn 386: }
1.2 raeburn 387:
1.1 raeburn 388: if ($numlocalcc > 0) {
389: @local_ccs = sort @local_ccs;
390: $ownertable = qq(
391: <input type="hidden" name="numlocalcc" value="$numlocalcc" />
392: <table>
393: <tr>
1.28 raeburn 394: <td>$lt{'tabl'} - $cdom ($domdesc). $lt{'usrd'}
1.1 raeburn 395: </td>
396: </tr>
397: <tr><td> </td></tr>
398: <tr>
1.28 raeburn 399: <td>).
400: &Apache::loncommon::start_data_table()."\n".
401: &Apache::loncommon::start_data_table_header_row()."\n".
402: "<th>$lt{'ownr'}</th>\n".
403: "<th>$lt{'name'}</th>\n".
404: "<th>$lt{'unme'}</th>\n".
405: "<th>$lt{'stus'}</th>\n".
406: &Apache::loncommon::end_data_table_header_row()."\n";
407: foreach my $cc (@local_ccs) {
408: $ownertable .= &Apache::loncommon::start_data_table_row()."\n";
409: if ($cc eq $enrollvar{'courseowner'}) {
410: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" checked="checked" /></td>'."\n";
1.1 raeburn 411: } else {
1.28 raeburn 412: $ownertable .= '<td><input type="radio" name="courseowner" value="'.$cc.'" /></td>'."\n";
1.1 raeburn 413: }
1.28 raeburn 414: $ownertable .=
415: '<td>'.$pname{$cc}.'</td>'."\n".
416: '<td>'.$cc.'</td>'."\n".
417: '<td>'.$cc_status{$cc}.' '.$lt{'ccor'}.'</td>'."\n".
418: &Apache::loncommon::end_data_table_row()."\n";
419: }
420: $ownertable .= &Apache::loncommon::end_data_table()."
1.1 raeburn 421: </td>
422: </tr>
423: </table>";
424: }
1.28 raeburn 425: &print_header($r,$cdesc,$javascript_validations);
426: my $type = $env{'form.type'};
1.29 raeburn 427: if ($type eq '') {
428: $type = 'Course';
429: }
1.28 raeburn 430: my $dctitle = &Apache::lonnet::plaintext('dc');
431: my $cctitle = &Apache::lonnet::plaintext('cc',$type);
432: my $mainheader = &mt('Course settings modifiable by [_1] only.',$dctitle);
433: my $hidden_elements = &hidden_form_elements();
1.1 raeburn 434: $r->print(<<ENDDOCUMENT);
1.28 raeburn 435: <form action="/adm/modifycourse" method="post" name="setparms">
436: <h3>$mainheader</h3>
1.1 raeburn 437: </p><p>
1.2 raeburn 438: <table width="100%" cellspacing="6" cellpadding="6">
439: <tr>
440: <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. Click the <b>"$lt{'gobt'}"</b> button to save your changes.</td>
441: </tr>
1.1 raeburn 442: <tr>
443: <td width="50%" valign="top">
1.2 raeburn 444: <b>$lt{'ccod'}:</b>
1.1 raeburn 445: <input type="text" size="10" name="coursecode" value="$enrollvar{'coursecode'}"/><br/><br/>
446: $lt{'ccus'}
447: </td>
448: <td width="50%" valign="top" rowspan="2">
1.2 raeburn 449: <b>$lt{'cown'}:</b><br/><br/>
450: $ownertable
451: <br/><br/>
1.1 raeburn 452: $lt{'cous'}
453: </td>
454: </tr>
455: <tr>
456: <td width="50%" valign="top">
1.2 raeburn 457: <b>$lt{'deam'}:</b><br/><br/>
458: $krbform
459: <br/>
460: $intform
461: <br/>
462: $locform
463: <br/>
464: <br/>
1.1 raeburn 465: $lt{'deus'}.
466: </td>
467: <td width="50%"> </td>
468: </tr>
469: </table>
470: <table width="90%" cellpadding="5" cellspacing="0">
471: <tr>
1.28 raeburn 472: <td align="left">
473: $hidden_elements
474: <input type="button" onClick="javascript:changePage(this.form,'processparms');javascript:verify_message(this.form)" value="$lt{'gobt'}" />
1.1 raeburn 475: </td>
476: </tr>
477: </table>
478: </form>
479: <br/>
480: <br/>
481: ENDDOCUMENT
1.5 raeburn 482: return;
1.1 raeburn 483: }
484:
485: sub modify_course {
1.30 ! raeburn 486: my ($r,$cdom,$cnum,$cdesc,$domdesc,$type) = @_;
1.28 raeburn 487: my %longtype = &course_settings_descrip();
488: my %settings = &Apache::lonnet::get('environment',['internal.courseowner','internal.coursecode','internal.authtype','internal.autharg','internal.sectionnums','internal.crosslistings','description'],$cdom,$cnum);
1.1 raeburn 489: my %currattr = ();
490: my %newattr = ();
491: my %cenv = ();
492: my $response;
493: my $chgresponse;
494: my $nochgresponse;
495: my $warning;
496: my $reply;
497: my @changes = ();
498: my @nochanges = ();
499: my @sections = ();
500: my @xlists = ();
501: my $changecode = 0;
502: my $changeowner = 0;
1.28 raeburn 503: unless ($settings{'internal.sectionnums'} eq '') {
1.1 raeburn 504: if ($settings{'internal.sectionnums'} =~ m/,/) {
505: @sections = split/,/,$settings{'internal.sectionnums'};
506: } else {
507: $sections[0] = $settings{'internal.sectionnums'};
508: }
509: }
510: unless ($settings{'internal.crosslistings'} eq'') {
511: if ($settings{'internal.crosslistings'} =~ m/,/) {
512: @xlists = split/,/,$settings{'internal.crosslistings'};
513: } else {
514: $xlists[0] = $settings{'internal.crosslistings'};
515: }
516: }
517:
1.28 raeburn 518: my @modifiable_params = &get_dc_settable();
519: foreach my $param (@modifiable_params) {
520: my $attr = 'internal.'.$param;
521: $currattr{$param} = $settings{$attr};
1.1 raeburn 522: }
523:
524: my $description = $settings{'description'};
525: my %cenv = ();
526:
1.16 albertel 527: if ($env{'form.login'} eq 'krb') {
528: $newattr{'authtype'} = $env{'form.login'};
529: $newattr{'authtype'} .= $env{'form.krbver'};
530: $newattr{'autharg'} = $env{'form.krbarg'};
531: } elsif ($env{'form.login'} eq 'int') {
1.1 raeburn 532: $newattr{'authtype'} ='internal';
1.16 albertel 533: if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
534: $newattr{'autharg'} = $env{'form.intarg'};
1.1 raeburn 535: }
1.16 albertel 536: } elsif ($env{'form.login'} eq 'loc') {
1.1 raeburn 537: $newattr{'authtype'} = 'localauth';
1.16 albertel 538: if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
539: $newattr{'autharg'} = $env{'form.locarg'};
1.1 raeburn 540: }
541: }
542: if ( $newattr{'authtype'}=~ /^krb/) {
543: if ($newattr{'autharg'} eq '') {
1.2 raeburn 544: $warning = qq(<font color="red" size="+1">).
545: &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 546: }
547: }
548:
1.16 albertel 549: if ( exists($env{'form.courseowner'}) ) {
550: $newattr{'courseowner'}=$env{'form.courseowner'};
1.14 raeburn 551: unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
552: $changeowner = 1;
1.1 raeburn 553: }
554: }
555:
1.16 albertel 556: if ( exists($env{'form.coursecode'}) ) {
557: $newattr{'coursecode'}=$env{'form.coursecode'};
1.1 raeburn 558: unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
559: $changecode = 1;
560: }
561: }
1.14 raeburn 562: if ($changeowner == 1 || $changecode == 1) {
1.30 ! raeburn 563: my $courseid_entry = &escape($cdom.'_'.$cnum).'='.&escape($description).':'.&escape($env{'form.coursecode'}).':'.&escape($env{'form.courseowner'}).':'.&escape($type);
1.28 raeburn 564: &Apache::lonnet::courseidput($cdom,$courseid_entry,&Apache::lonnet::homeserver($cnum,$cdom));
1.14 raeburn 565: }
1.1 raeburn 566:
1.28 raeburn 567: foreach my $param (@modifiable_params) {
568: if ($currattr{$param} eq $newattr{$param}) {
569: push(@nochanges,$param);
1.1 raeburn 570: } else {
1.28 raeburn 571: my $attr = 'internal.'.$param;
572: $cenv{$attr} = $newattr{$param};
573: push(@changes,$param);
1.1 raeburn 574: }
575: }
576:
577: if (@changes > 0) {
1.2 raeburn 578: $chgresponse = &mt("The following automated enrollment parameters have been changed:<br/><ul>");
1.1 raeburn 579: }
580: if (@nochanges > 0) {
1.2 raeburn 581: $nochgresponse = &mt("The following automated enrollment parameters remain unchanged:<br/><ul>");
1.1 raeburn 582: }
583: if (@changes > 0) {
1.28 raeburn 584: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,$cnum);
1.1 raeburn 585: if ($putreply !~ /^ok$/) {
1.2 raeburn 586: $response = &mt("There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>");
1.1 raeburn 587: } else {
1.28 raeburn 588: foreach my $attr (@modifiable_params) {
1.1 raeburn 589: if (grep/^$attr$/,@changes) {
1.28 raeburn 590: $chgresponse .= "<li>$longtype{$attr} ".&mt("now set to \"").$newattr{$attr}."\".</li>";
1.1 raeburn 591: } else {
1.28 raeburn 592: $nochgresponse .= "<li>$longtype{$attr} ".&mt("still set to \"").$currattr{$attr}."\".</li>";
1.1 raeburn 593: }
594: }
595: if ($changecode || $changeowner) {
596: if ( $newattr{'courseowner'} eq '') {
1.2 raeburn 597: $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 598: } else {
599: if (@sections > 0) {
1.2 raeburn 600: if ($changecode) {
601: foreach my $sec (@sections) {
602: if ($sec =~ m/^(.+):/) {
1.8 raeburn 603: my $inst_course_id = $newattr{'coursecode'}.$1;
1.28 raeburn 604: my $course_check = &Apache::lonnet::auto_validate_courseID($cnum,$cdom,$inst_course_id);
1.7 raeburn 605: if ($course_check eq 'ok') {
1.28 raeburn 606: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
1.1 raeburn 607: unless ($outcome eq 'ok') {
1.2 raeburn 608: $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 609: }
610: } else {
1.2 raeburn 611: $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 612: }
613: } else {
1.2 raeburn 614: $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 615: }
616: }
1.4 raeburn 617: } elsif ($changeowner) {
618: foreach my $sec (@sections) {
619: if ($sec =~ m/^(.+):/) {
1.8 raeburn 620: my $inst_course_id = $newattr{'coursecode'}.$1;
1.28 raeburn 621: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$inst_course_id,$newattr{'courseowner'});
1.4 raeburn 622: unless ($outcome eq 'ok') {
623: $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/>");
624: }
625: } else {
626: $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/>");
627: }
628: }
629: }
1.1 raeburn 630: } else {
1.2 raeburn 631: $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 632: }
633: if ( (@xlists > 0) && ($changeowner) ) {
634: foreach my $xlist (@xlists) {
635: if ($xlist =~ m/^(.+):/) {
1.28 raeburn 636: my $outcome = &Apache::lonnet::auto_new_course($cnum,$cdom,$1,$newattr{'courseowner'});
1.1 raeburn 637: unless ($outcome eq 'ok') {
1.2 raeburn 638: $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 639: }
1.28 raeburn 640: }
1.1 raeburn 641: }
642: }
643: }
644: }
645: }
1.2 raeburn 646: } else {
1.28 raeburn 647: foreach my $attr (@modifiable_params) {
648: $nochgresponse .= "<li>$longtype{$attr} ".&mt("still set to")." \"".$currattr{$attr}."\".</li>";
1.2 raeburn 649: }
1.1 raeburn 650: }
651:
652: if (@changes > 0) {
653: $chgresponse .= "</ul><br/><br/>";
654: }
655: if (@nochanges > 0) {
656: $nochgresponse .= "</ul><br/><br/>";
657: }
658: unless ($warning eq '') {
1.2 raeburn 659: $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 660: }
661: if ($response eq '') {
662: $reply = $chgresponse.$nochgresponse.$warning;
663: } else {
664: $reply = $response;
665: }
1.28 raeburn 666: &print_header($r,$cdesc);
667: $reply = '<h3>'.
668: &mt('Result of Changes to Automated Enrollment Settings.').
669: '</h3>'."\n".
670: '<table><tr><td>'.$reply.'</td></tr></table>'.
671: '<form action="/adm/modifycourse" method="post" name="processparms">'.
672: &hidden_form_elements().
673: '<a href="javascript:changePage(document.processparms,'."'menu'".')">'.&mt('Back to options page').'</a>
674: </form>';
1.3 raeburn 675: $r->print($reply);
1.28 raeburn 676: return;
677: }
678:
679: sub modify_quota {
680: my ($r,$cdom,$cnum,$cdesc,$domdesc) = @_;
681: &print_header($r,$cdesc);
682:
683: my %lt = &Apache::lonlocal::texthash(
684: 'back' => 'Back to options page',
685: );
686: $r->print('
687: <form action="/adm/modifycourse" method="post" name="processquota">
688: <h3>'.&mt('Disk space for storage of group portfolio files for [_1]',$cdesc).
689: '</h3>');
690: my %oldsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
691: my $defaultquota = 20;
692: if ($env{'form.coursequota'} ne '') {
693: my $newquota = $env{'form.coursequota'};
694: if ($newquota =~ /^\s*(\d+\.?\d*|\.\d+)\s*$/) {
695: $newquota = $1;
696: if ($oldsettings{'internal.coursequota'} eq $env{'form.coursequota'}) {
697: $r->print(&mt('The disk space allocated for group portfolio files remains unchanged as ').$env{'form.coursequota'}.' Mb');
698: } else {
699: my %cenv = (
700: 'internal.coursequota' => $env{'form.coursequota'},
701: );
702: my $putreply = &Apache::lonnet::put('environment',\%cenv,$cdom,
703: $cnum);
704: if (($oldsettings{'internal.coursequota'} eq '') &&
705: ($env{'form.coursequota'} == $defaultquota)) {
706: $r->print(&mt('The disk space allocated for group portfolio files in this course is the default quota for this domain:').' '.$defaultquota.' Mb');
707: } else {
708: if ($putreply eq 'ok') {
709: my %updatedsettings = &Apache::lonnet::get('environment',['internal.coursequota'],$cdom,$cnum);
710: $r->print(&mt('The disk space allocated for group portfolio files is now:').' '.$updatedsettings{'internal.coursequota'}.' Mb.');
711: my $usage = &Apache::longroup::sum_quotas($cdom.'_'.$cnum);
712: if ($usage >= $updatedsettings{'internal.coursequota'}) {
713: my $newoverquota;
714: if ($usage < $oldsettings{'internal.coursequota'}) {
715: $newoverquota = 'now';
716: }
717: $r->print('<br /><br />'.
718: &mt('Disk usage [_1] exceeds the quota for this course.',$newoverquota).' '.
719: &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.'));
720: }
721: } else {
722: $r->print(&mt('There was an error'));
723: }
724: }
725: }
726: } else {
727: $r->print(&mt('The new quota requested contained invalid characters, so the quota is unchanged.'));
728: }
729: }
730: $r->print(qq|<br /><br />
731: <a href="javascript:changePage(document.processquota,'menu')">$lt{'back'}</a>|);
732: $r->print(&hidden_form_elements().'</form>');
733: return;
1.1 raeburn 734: }
735:
736: sub print_header {
1.28 raeburn 737: my ($r,$cdesc,$javascript_validations) = @_;
738: my $phase = "start";
739: if ( exists($env{'form.phase'}) ) {
740: $phase = $env{'form.phase'};
741: }
742: my $js = qq|
743: <script type="text/javascript">
744: function changePage(formname,newphase) {
745: formname.phase.value = newphase;
746: if (newphase == 'processparms') {
747: return;
1.1 raeburn 748: }
1.28 raeburn 749: formname.submit();
750: }
751: </script>
752: |;
753: if ($phase eq 'setparms') {
754: $js .= qq|
755: <script type="text/javascript">
756: $javascript_validations
757: </script>
758: |;
759: } elsif ($phase eq 'courselist') {
760: $js .= qq|
761: <script type="text/javascript">
762: function gochoose(cname,cdom,cdesc) {
763: document.courselist.pickedcourse.value = cdom+'_'+cname;
764: document.courselist.submit();
765: }
766: </script>
767: |;
768: } elsif ($phase eq 'setquota') {
769: $js .= <<'ENDSCRIPT';
770: <script type="text/javascript">
771: function verify_quota(formname) {
772: var newquota = formname.coursequota.value;
773: var num_reg = /^\s*(\d+\.?\d*|\.\d+)\s*$/;
774: if (num_reg.test(newquota)) {
775: changePage(formname,'processquota');
1.1 raeburn 776: } else {
1.28 raeburn 777: alert("The quota you entered contained invalid characters.\nYou must enter a number");
1.1 raeburn 778: }
1.28 raeburn 779: return;
780: }
781: </script>
782: ENDSCRIPT
1.1 raeburn 783: }
1.23 albertel 784: $r->print(&Apache::loncommon::start_page('View/Modify Course Settings',
785: $js));
1.28 raeburn 786: my $bread_text = "View/Modify Courses";
787: if ($cdesc ne '') {
788: $bread_text = "Course Settings: $cdesc";
789: }
790: $r->print(&Apache::lonhtmlcommon::breadcrumbs($bread_text));
1.5 raeburn 791: return;
1.1 raeburn 792: }
793:
794: sub print_footer {
1.23 albertel 795: my ($r) = @_;
796: $r->print('<br />'.&Apache::loncommon::end_page());
1.5 raeburn 797: return;
1.3 raeburn 798: }
799:
800: sub check_course {
1.28 raeburn 801: my ($r,$dom,$domdesc) = @_;
802: my ($ok_course,$description,$instcode,$owner);
803: if (defined($env{'form.pickedcourse'})) {
804: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
805: if ($cdom eq $dom) {
806: my %courseIDs = &Apache::lonnet::courseiddump($cdom,'.',1,'.','.',
807: $cnum,undef,undef,'.');
808: if (keys(%courseIDs) > 0) {
809: $ok_course = 'ok';
810: ($description,$instcode,$owner) =
811: split(/:/,$courseIDs{$cdom.'_'.$cnum});
812: $description = &unescape($description);
813: $instcode = &unescape($instcode);
814: if ($instcode) {
815: $description .= " ($instcode)";
816: }
1.5 raeburn 817: }
1.3 raeburn 818: }
819: }
1.28 raeburn 820:
821: if ($ok_course ne 'ok') {
822: $r->print('<br/>'.&mt('The LON-CAPA course selected was not a valid course for the [_1] domain',$domdesc));
823: }
824: return ($ok_course,$description);
1.1 raeburn 825: }
826:
1.28 raeburn 827: sub course_settings_descrip {
828: my %longtype = &Apache::lonlocal::texthash(
829: 'authtype' => 'Default authentication method',
830: 'autharg' => 'Default authentication parameter',
831: 'autoadds' => 'Automated adds',
832: 'autodrops' => 'Automated drops',
833: 'autostart' => 'Date of first automated enrollment',
834: 'autoend' => 'Date of last automated enrollment',
835: 'default_enrollment_start_date' => 'Date of first student access',
836: 'default_enrollment_end_date' => 'Date of last student access',
837: 'coursecode' => 'Official course code',
838: 'courseowner' => "Username:domain of course owner",
839: 'notifylist' => 'Course Coordinators to be notified of enrollment changes',
840: 'sectionnums' => 'Course section number(:LON-CAPA section)',
841: 'crosslistings' => 'Crosslisted class(:LON-CAPA section)',
842: );
843: return %longtype;
844: }
845:
846: sub hidden_form_elements {
847: my $hidden_elements =
848: &Apache::lonhtmlcommon::echo_form_input(['gosearch','coursecode',
849: 'numlocalcc','courseowner',
850: 'login','coursequota','intarg', 'locarg','krbarg','krbver']);
851: return $hidden_elements;
852: }
1.1 raeburn 853:
854: sub handler {
855: my $r = shift;
856: if ($r->header_only) {
857: &Apache::loncommon::content_type($r,'text/html');
858: $r->send_http_header;
859: return OK;
860: }
1.28 raeburn 861: my $dom = $env{'request.role.domain'};
862: my $domdesc = $Apache::lonnet::domaindescription{$dom};
863: if (&Apache::lonnet::allowed('ccc',$dom)) {
1.1 raeburn 864: &Apache::loncommon::content_type($r,'text/html');
865: $r->send_http_header;
866:
1.28 raeburn 867: &Apache::lonhtmlcommon::clear_breadcrumbs();
868:
869: my $phase = $env{'form.phase'};
870: &Apache::lonhtmlcommon::add_breadcrumb
871: ({href=>"/adm/modifycourse",
872: text=>"Course search"});
873: if ($phase eq '') {
874: &print_course_search_page($r,$dom,$domdesc);
1.1 raeburn 875: } else {
1.28 raeburn 876: &Apache::lonhtmlcommon::add_breadcrumb
877: ({href=>"javascript:changePage(document.$phase,'courselist')",
878: text=>"Choose a course"});
879: if ($phase eq 'courselist') {
880: &print_course_selection_page($r,$dom,$domdesc);
881: } else {
882: &Apache::lonhtmlcommon::add_breadcrumb
883: ({href=>"javascript:changePage(document.$phase,'menu')",
884: text=>"Pick action"});
885: my ($checked,$cdesc) = &check_course($r,$dom,$domdesc);
886: my $type = $env{'form.type'};
1.29 raeburn 887: if ($type eq '') {
888: $type = 'Course';
889: }
1.28 raeburn 890: if ($checked eq 'ok') {
891: if ($phase eq 'menu') {
892: &print_modification_menu($r,$cdesc);
893: } else {
894: my ($cdom,$cnum) = split(/_/,$env{'form.pickedcourse'});
895: if ($phase eq 'setquota') {
896: &Apache::lonhtmlcommon::add_breadcrumb
897: ({href=>"javascript:changePage(document.$phase,'$phase')",
898: text=>"Set quota"});
899: &print_setquota($r,$cdom,$cnum,$cdesc,$type)
900: } elsif ($phase eq 'processquota') {
901: &Apache::lonhtmlcommon::add_breadcrumb
902: ({href=>"javascript:changePage(document.$phase,'setquota')",
903: text=>"Set quota"});
904: &Apache::lonhtmlcommon::add_breadcrumb
905: ({href=>"javascript:changePage(document.$phase,'$phase')",
906: text=>"Result"});
907: &modify_quota($r,$cdom,$cnum,$cdesc,$domdesc);
908: } elsif ($phase eq 'viewparms') {
909: &Apache::lonhtmlcommon::add_breadcrumb
910: ({href=>"javascript:changePage(document.$phase,'viewparms')",
911: text=>"Display settings"});
912: &print_settings_display($r,$cdom,$cnum,$cdesc,$type);
913: } elsif ($phase eq 'setparms') {
914: &Apache::lonhtmlcommon::add_breadcrumb
915: ({href=>"javascript:changePage(document.$phase,'$phase')",
916: text=>"Change settings"});
917: &print_course_modification_page($r,$cdom,$cnum,$cdesc,$domdesc);
918: } elsif ($phase eq 'processparms') {
919: &Apache::lonhtmlcommon::add_breadcrumb
920: ({href=>"javascript:changePage(document.$phase,'setparms')",
921: text=>"Change settings"});
922: &Apache::lonhtmlcommon::add_breadcrumb
923: ({href=>"javascript:changePage(document.$phase,'$phase')",
924: text=>"Result"});
1.30 ! raeburn 925: &modify_course($r,$cdom,$cnum,$cdesc,$domdesc,$type);
1.28 raeburn 926: }
927: }
928: } else {
929: $r->print(&mt('The course you selected is not a valid course in this domain')." ($domdesc)");
930: }
931: }
1.1 raeburn 932: }
1.28 raeburn 933: &print_footer($r);
1.1 raeburn 934: } else {
1.16 albertel 935: $env{'user.error.msg'}=
1.2 raeburn 936: "/adm/modifycourse:ccc:0:0:Cannot modify course settings";
1.1 raeburn 937: return HTTP_NOT_ACCEPTABLE;
938: }
939: return OK;
940: }
941:
942: 1;
943: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>