File:
[LON-CAPA] /
loncom /
interface /
lonmodifycourse.pm
Revision
1.9:
download - view:
text,
annotated -
select for diffs
Thu Jun 17 18:31:24 2004 UTC (20 years, 2 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
Calls to functions in localenroll.pm mediated by lonc/lond now include domain
in the set of passed parameters to support domain-specific variants in a single
localenroll.pm file housed on a multi-domain library server.
Automated enrollment now sets first access and last access dates for student
roles based on defaults set on course creation, and modifiable via a number
of mechanisms in the Enrollment Manager, and Automated Enrollment Manager.
The Automated Enrollment Manager now provides a utility to allow enrollment type
to be toggled between 'auto' and 'manual', so that students added via CSV file
or singly can become liable for automated update (dropping, section switching
etc.).
1: # Copyright Michigan State University Board of Trustees
2: #
3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
4: #
5: # LON-CAPA is free software; you can redistribute it and/or modify
6: # it under the terms of the GNU General Public License as published by
7: # the Free Software Foundation; either version 2 of the License, or
8: # (at your option) any later version.
9: #
10: # LON-CAPA is distributed in the hope that it will be useful,
11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: # GNU General Public License for more details.
14: #
15: # You should have received a copy of the GNU General Public License
16: # along with LON-CAPA; if not, write to the Free Software
17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: #
19: # /home/httpd/html/adm/gpl.txt
20: #
21: # http://www.lon-capa.org/
22: #
23: package Apache::lonmodifycourse;
24:
25: use strict;
26: use Apache::Constants qw(:common :http);
27: use Apache::lonnet;
28: use Apache::loncommon;
29: use Apache::lonlocal;
30: use Apache::londropadd;
31: use LONCAPA::Enrollment;
32: use lib '/home/httpd/lib/perl';
33: use localenroll;
34:
35: sub print_course_selection_page {
36: my ($r,$tasklongref) = @_;
37: my $dom = $ENV{'user.domain'};
38: my %lt=&Apache::lonlocal::texthash(
39: 'csae' => "Course settings for automated enrollment",
40: 'unst' => "Unlike standard LON-CAPA course parameters, such as course description, feedback addresses, and top level map, which are displayed and/or modified using the 'Course Environment Parameters' screen, settings that control automated enrollment based on classlist data available from your institution's student information system are handled differently. Automated enrollment settings fall into two groups: (a) settings that can be modified by a Course Coordinator using the Automated Enrollment Manager and (b) settings that may only be modified by a Domain Coordinator via the 'View/Modify Course settings' menu accessed from this page.",
41: 'chcs' => "Choose the course for which you wish to view/modify automated enrollment settings from the select box below and click 'Go' to proceed.",
42: 'eaen' => "Each entry in the select box contains: <b>course code</b> -- <b>course title</b> ------- <b>course owner</b>, and entries are ordered alphabetically by course code.",
43: 'psac' => "Please select a course",
44: 'ccrs' => "Choose a course",
45: 'gobt' => "Go"
46: );
47:
48: # Determine the courses
49: my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1);
50: &print_header($r,$tasklongref);
51: $r->print(<<ENDBLOCK);
52: <form action="/adm/modifycourse" method="post" name="cmod">
53: <h3>$lt{'csae'}</h3>
54: <p>$lt{'unst'}
55: </p><p>$lt{'chcs'}
56: <br/>$lt{'eaen'}
57: </p><p>
58: <b>$lt{'ccrs'}:</b>
59: <select name="course">
60: <option value="0" />$lt{'psac'}
61: <option value="-1" />---------------------------------------------------
62: ENDBLOCK
63: my $iter = 0;
64: my @codes = ();
65: my %courses = ();
66: foreach my $key (sort keys %courseIDs) {
67: # Get current code
68: my $crs;
69: my $currcode;
70: if ($key =~ m/^($dom)_(\w+)$/) {
71: $crs = $2;
72: my %settings = &Apache::lonnet::get('environment',['internal.coursecode'],$dom,$crs);
73: if (defined($settings{'internal.coursecode'}) ) {
74: $currcode = $settings{'internal.coursecode'};
75: if ($currcode eq '') {
76: $currcode = "___".$iter;
77: $iter ++;
78: }
79: } else {
80: $currcode = "___".$iter;
81: $iter ++;
82: }
83: } else {
84: $currcode = "___".$iter;
85: $iter ++;
86: }
87: unless (grep/^$currcode$/,@codes) {
88: push @codes,$currcode;
89: @{$courses{$currcode}} = ();
90: }
91: push @{$courses{$currcode}}, $key;
92: }
93: foreach my $code (sort @codes) {
94: foreach my $item (@{$courses{$code}}) {
95: my $crs;
96: my $owner;
97: my $ownername;
98: my $description;
99: my $showcode = '';
100: unless ($code =~m/^___\d+$/) { $showcode = $code; }
101: if ($item =~ m/^($dom)_(\w+)$/) {
102: $crs = $2;
103: $description = $courseIDs{$item};
104: # Get course owner
105: my %settings = &Apache::lonnet::get('environment',['internal.courseowner'],$dom,$crs);
106: if ( defined($settings{'internal.courseowner'}) ) {
107: $owner = $settings{'internal.courseowner'};
108: $ownername = &Apache::loncommon::plainname($owner,$dom);
109: }
110: $r->print("<option value=\"$crs\">$showcode -- $description ---------- $ownername");
111: }
112: }
113: }
114: $r->print("</select>
115:
116: <input type=\"hidden\" name=\"action\" value=\"display\" />
117: <input type=\"button\" onClick=\"this.form.submit()\" value=\"$lt{'gobt'}\" />
118: </p>
119: </form>");
120: &print_footer($r);
121: return;
122: }
123:
124: sub print_course_modification_page {
125: my ($r,$tasklongref,$typeref) = @_;
126: my %enrollvar = ();
127: my $javascript_validations;
128: my $course = '';
129: my $dom = $ENV{'user.domain'};
130: if ( defined($ENV{'form.course'}) ) {
131: $course = $ENV{'form.course'};
132: }
133: my $ok_course = 'ok';
134: if ( ($course == -1) || ($course == '-2') || ($course eq '') ) {
135: $ok_course = 'invalid';
136: } else {
137: $ok_course = &check_course($dom,$course);
138: }
139:
140: unless ($ok_course eq 'ok') {
141: &print_header($r,$tasklongref,'',\$javascript_validations);
142: my $reply = "<br/>".&mt("The LON-CAPA course selected was not a valid course for this domain");
143: $r->print($reply);
144: &print_footer($r);
145: return;
146: }
147:
148: my @bgcolors=("#eeeeee","#cccccc");
149: my $ownertable;
150: my %lt=&Apache::lonlocal::texthash(
151: 'actv' => "Active",
152: 'inac' => "Inactive",
153: 'ccor' => "Course Coordinator",
154: 'noen' => "No end date",
155: 'ownr' => "Owner",
156: 'name' => "Name",
157: 'unme' => "Username",
158: 'stus' => "Status",
159: 'aecs' => "Automated Enrollment Course Settings",
160: '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 ",
161: 'aenm' => "Automated Enrollment Manager",
162: 'andb' => " and (b) settings that may only be modified by a Domain Coordinator via this page.",
163: 'caes' => 'Current automated enrollment settings',
164: 'cour' => "Course settings that control automated enrollment in this LON-CAPA course
165: are currently:",
166: 'cset' => "Course setting",
167: 'valu' => "Current value",
168: '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.",
169: 'ccus' => "A course coordinator can use the 'Automated Enrollment Manager' to change
170: 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).",
171: 'mkch' => "Make changes to course settings set by Domain Coordinator",
172: 'ccod' => "Course Code",
173: '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.",
174: 'cown' => "Course Owner",
175: '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.",
176: 'tabl' => 'The table below contains a list of active course coordinators in this course, who are from this domain',
177: 'usrd' => 'Use the radio buttons to select a different course owner.',
178: 'deam' => "Default Authentication method",
179: '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.",
180: 'gobt' => "Modify settings",
181: );
182:
183: my %settings = &Apache::lonnet::dump('environment',$dom,$course);
184: $enrollvar{'autharg'} = '';
185: $enrollvar{'authtype'} = '';
186: foreach my $item (keys %settings) {
187: if ($item =~ m/^internal\.(.+)$/) {
188: if ( ($1 eq "autoadds") || ($1 eq "autodrops") ) {
189: if ($settings{$item} == 1) {
190: $enrollvar{$1} = "ON";
191: } else {
192: $enrollvar{$1} = "OFF";
193: }
194: } elsif ( ($1 eq "autostart") || ($1 eq "autoend") ) {
195: if ( ($1 eq "autoend") && ($settings{$item} == 0) ) {
196: $enrollvar{$1} = $lt{'noen'};
197: } else {
198: $enrollvar{$1} = localtime($settings{$item});
199: }
200: } elsif ($1 eq "courseowner" || $1 eq "authtype" || $1 eq "autharg" || $1 eq "sectionnums" || $1 eq "coursecode" || $1 eq "crosslistings") {
201: $enrollvar{$1} = $settings{$item};
202: }
203: } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
204: if ( ($1 eq 'end') && ($settings{$item} == 0) ) {
205: $enrollvar{$item} = $lt{'noen'};
206: } elsif ( ($1 eq 'start') && ($settings{$item} eq '') ) {
207: $enrollvar{$item} = 'When enrolled';
208: } else {
209: $enrollvar{$item} = localtime($settings{$item});
210: }
211: }
212: }
213:
214: my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$course);
215: my @local_ccs = ();
216: my %cc_status = ();
217: my %pname = ();
218: my $active_cc;
219: foreach (@coursepersonnel) {
220: my @roleinfo = split/:/,$_;
221: if ( ($roleinfo[0] eq 'cc') && ($roleinfo[2] eq $dom) ) {
222: unless (grep/^$roleinfo[1]$/,@local_ccs) {
223: $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$course,'cc');
224: if ($active_cc eq 'ok') {
225: push @local_ccs, $roleinfo[1];
226: $pname{$roleinfo[1]} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
227: $cc_status{$roleinfo[1]} = $lt{'actv'};
228: }
229: }
230: }
231: }
232: unless ( (grep/^$enrollvar{'courseowner'}$/,@local_ccs) || ($enrollvar{'courseowner'} eq '') ) {
233: push @local_ccs, $enrollvar{'courseowner'};
234: $pname{$enrollvar{'courseowner'}} = &Apache::loncommon::plainname($enrollvar{'courseowner'},$dom);
235: $active_cc = &LONCAPA::Enrollment::check_user_status($dom,$enrollvar{'coursecode'},$dom,$course,'cc');
236: if ($active_cc eq 'ok') {
237: $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
238: } else {
239: $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
240: }
241: }
242: my $numlocalcc = @local_ccs;
243: my $bodytag=&Apache::loncommon::bodytag(&mt("Modify Course Settings"));
244: my $helplink=&Apache::loncommon::help_open_topic('Modify_Course',&mt("Help on Modifying Courses"));
245: my $defdom=$ENV{'request.role.domain'};
246: my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($defdom);
247: my $curr_authtype = '';
248: my $curr_authfield = '';
249: if ($enrollvar{'authtype'} =~ /^krb/) {
250: $curr_authtype = 'krb';
251: } elsif ($enrollvar{'authtype'} eq 'internal' ) {
252: $curr_authtype = 'int';
253: } elsif ($enrollvar{'authtype'} eq 'localauth' ) {
254: $curr_authtype = 'loc';
255: }
256: unless ($curr_authtype eq '') {
257: $curr_authfield = $curr_authtype.'arg';
258: }
259: $javascript_validations=&Apache::londropadd::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield);
260: my %param = ( formname => 'document.cmod',
261: kerb_def_dom => $krbdefdom,
262: kerb_def_auth => $krbdef,
263: mode => 'modifycourse',
264: curr_authtype => $curr_authtype,
265: curr_autharg => $enrollvar{'autharg'}
266: );
267: my $krbform = &Apache::loncommon::authform_kerberos(%param);
268: my $intform = &Apache::loncommon::authform_internal(%param);
269: my $locform = &Apache::loncommon::authform_local(%param);
270:
271: my $disp_table = qq|<table border="0" cellpadding="0" cellspacing="0">
272: <tr>
273: <td width="100%" bgcolor="#000000">
274: <table width="100%" border="0" cellpadding="1" cellspacing="0">
275: <tr>
276: <td width="100%" bgcolor="#000000">
277: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
278: <tr bgcolor="#CCCC99" align="center">
279: <td><b>$lt{'cset'}</b></td>
280: <td><b>$lt{'valu'}</b></td>
281: </tr>
282: |;
283: my $iter = 0;
284: foreach my $key (sort keys %enrollvar) {
285: my $colflag = $iter%2;
286: $disp_table .= "<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
287: <td>$$typeref{$key}</td>
288: <td>$enrollvar{$key}</td>
289: </tr>";
290: $iter ++;
291: }
292: $disp_table .= "</table>
293: </td>
294: </tr>
295: </table>
296: </td>
297: </tr>
298: </table>";
299:
300: if ($numlocalcc == 0) {
301: $ownertable = $lt{'nocc'};
302: }
303:
304: if ($numlocalcc > 0) {
305: @local_ccs = sort @local_ccs;
306: $ownertable = qq(
307: <input type="hidden" name="numlocalcc" value="$numlocalcc" />
308: <table>
309: <tr>
310: <td>$lt{'tabl'} ($dom). $lt{'usrd'}
311: </td>
312: </tr>
313: <tr><td> </td></tr>
314: <tr>
315: <td>
316: <table border="0" cellpadding="0" cellspacing="0">
317: <tr>
318: <td width="100%" bgcolor="#000000">
319: <table width="100%" border="0" cellpadding="1" cellspacing="0">
320: <tr>
321: <td width="100%" bgcolor="#000000">
322: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
323: <tr bgcolor="#CCCC99" align="center">
324: <td><b>$lt{'ownr'}</b></td>
325: <td><b>$lt{'name'}</b></td>
326: <td><b>$lt{'unme'}</b></td>
327: <td><b>$lt{'stus'}</b></td>
328: </tr>
329: );
330: for (my $i=0; $i<@local_ccs; $i++) {
331: my $colflag = $i%2;
332: $ownertable .= "<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">";
333: if ($local_ccs[$i] eq $enrollvar{'courseowner'}) {
334: $ownertable .= "<td><input type=\"radio\" name=\"courseowner\" value=\"$i\" checked=\"true\"/></td>";
335: } else {
336: $ownertable .= "<td><input type=\"radio\" name=\"courseowner\" value=\"$i\" /></td>";
337: }
338: $ownertable .= "
339: <td>$pname{$local_ccs[$i]}</td>
340: <td><input type=\"hidden\" name=\"username_$i\" value=\"$local_ccs[$i]\" />$local_ccs[$i]</td>
341: <td>$cc_status{$local_ccs[$i]} $lt{'ccor'}</td></tr>";
342: }
343: $ownertable .= "</table>
344: </td>
345: </tr>
346: </table>
347: </td>
348: </tr>
349: </table>
350: </td>
351: </tr>
352: </table>";
353: }
354: &print_header($r,$tasklongref,$settings{'description'},\$javascript_validations);
355: $r->print(<<ENDDOCUMENT);
356: <form action="/adm/modifycourse" method="post" name="cmod">
357: <h3>$lt{'aecs'}</h3>
358: $lt{'cose'}<a href="/adm/populate">$lt{'aenm'}</a>$lt{'andb'}
359: <p>
360: <table width="100%" cellspacing="0" cellpadding="0">
361: <tr>
362: <td bgcolor="#CCCC99"> </td>
363: <td align="left" bgcolor="#CCCC99"><h3>$lt{'caes'}</h3></td>
364: </tr>
365: </table>
366: <p>
367: $lt{'cour'}
368: </p><p>
369: $disp_table
370: <br/<br/>
371: </p><p>
372:
373: <table width="100%" cellspacing="0" cellpadding="0">
374: <tr>
375: <td bgcolor="#CCCC99"> </td>
376: <td align="left" bgcolor="#CCCC99">
377: <h3>$lt{'mkch'}</h3>
378: </td>
379: </tr>
380: </table>
381: </p><p>
382: <table width="100%" cellspacing="6" cellpadding="6">
383: <tr>
384: <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>
385: </tr>
386: <tr>
387: <td width="50%" valign="top">
388: <b>$lt{'ccod'}:</b>
389: <input type="text" size="10" name="coursecode" value="$enrollvar{'coursecode'}"/><br/><br/>
390: $lt{'ccus'}
391: </td>
392: <td width="50%" valign="top" rowspan="2">
393: <b>$lt{'cown'}:</b><br/><br/>
394: $ownertable
395: <br/><br/>
396: $lt{'cous'}
397: </td>
398: </tr>
399: <tr>
400: <td width="50%" valign="top">
401: <b>$lt{'deam'}:</b><br/><br/>
402: $krbform
403: <br/>
404: $intform
405: <br/>
406: $locform
407: <br/>
408: <br/>
409: $lt{'deus'}.
410: </td>
411: <td width="50%"> </td>
412: </tr>
413: </table>
414: <br/><br/>
415: <table width="90%" cellpadding="5" cellspacing="0">
416: <tr>
417: <td align="right">
418: <input type="hidden" name="course" value="$course" />
419: <input type="hidden" name="action" value="process" />
420: <input type="button" onClick="verify_message(this.form)" value="$lt{'gobt'}" />
421: </td>
422: </tr>
423: </table>
424: </form>
425: <br/>
426: <br/>
427: ENDDOCUMENT
428: &print_footer($r);
429: return;
430: }
431:
432: sub modify_course {
433: my ($r,$tasklongref,$typeref) = @_;
434: my $dom = $ENV{'user.domain'};
435: my $crs = $ENV{'form.course'};
436: unless ( &check_course($dom,$crs) eq 'ok' ) {
437: &print_header($r,$tasklongref);
438: my $reply = "<br/>".&mt("The LON-CAPA course selected was not a valid course for this domain");
439: $r->print($reply);
440: &print_footer($r);
441: return;
442: }
443:
444: my %settings = &Apache::lonnet::get('environment',['internal.courseowner','internal.coursecode','internal.authtype','internal.autharg','internal.sectionnums','internal.crosslistings','description'],$dom,$crs);
445: my %currattr = ();
446: my %newattr = ();
447: my %cenv = ();
448: my $response;
449: my $chgresponse;
450: my $nochgresponse;
451: my $warning;
452: my $reply;
453: my @changes = ();
454: my @nochanges = ();
455: my @sections = ();
456: my @xlists = ();
457: my $changecode = 0;
458: my $changeowner = 0;
459: unless ($settings{'internal.sectionnums'} eq'') {
460: if ($settings{'internal.sectionnums'} =~ m/,/) {
461: @sections = split/,/,$settings{'internal.sectionnums'};
462: } else {
463: $sections[0] = $settings{'internal.sectionnums'};
464: }
465: }
466: unless ($settings{'internal.crosslistings'} eq'') {
467: if ($settings{'internal.crosslistings'} =~ m/,/) {
468: @xlists = split/,/,$settings{'internal.crosslistings'};
469: } else {
470: $xlists[0] = $settings{'internal.crosslistings'};
471: }
472: }
473:
474: my @params = ('courseowner','coursecode','authtype','autharg');
475: foreach (@params) {
476: my $attr = 'internal.'.$_;
477: $currattr{$_} = $settings{$attr};
478: }
479:
480: my $description = $settings{'description'};
481: my %cenv = ();
482:
483: if ($ENV{'form.login'} eq 'krb') {
484: $newattr{'authtype'} = $ENV{'form.login'};
485: $newattr{'authtype'} .= $ENV{'form.krbver'};
486: $newattr{'autharg'} = $ENV{'form.krbarg'};
487: $newattr{'autharg'} =~ tr/a-z/A-Z/;
488: } elsif ($ENV{'form.login'} eq 'int') {
489: $newattr{'authtype'} ='internal';
490: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
491: $newattr{'autharg'} = $ENV{'form.intarg'};
492: }
493: } elsif ($ENV{'form.login'} eq 'loc') {
494: $newattr{'authtype'} = 'localauth';
495: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
496: $newattr{'autharg'} = $ENV{'form.locarg'};
497: }
498: }
499: if ( $newattr{'authtype'}=~ /^krb/) {
500: if ($newattr{'autharg'} eq '') {
501: $warning = qq(<font color="red" size="+1">).
502: &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>);
503: }
504: }
505:
506: if ( exists($ENV{'form.courseowner'}) ) {
507: my $ownerparam = 'username_'.$ENV{'form.courseowner'};
508: if ( exists($ENV{"form.$ownerparam"}) ) {
509: $newattr{'courseowner'}=$ENV{"form.$ownerparam"};
510: unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
511: $changeowner = 1;
512: }
513: }
514: }
515:
516: if ( exists($ENV{'form.coursecode'}) ) {
517: $newattr{'coursecode'}=$ENV{'form.coursecode'};
518: unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
519: $changecode = 1;
520: }
521: }
522:
523: foreach (@params) {
524: if ($currattr{$_} eq $newattr{$_}) {
525: push @nochanges, $_;
526: } else {
527: my $attr = 'internal.'.$_;
528: $cenv{$attr} = $newattr{$_};
529: push @changes, $_;
530: }
531: }
532:
533: if (@changes > 0) {
534: $chgresponse = &mt("The following automated enrollment parameters have been changed:<br/><ul>");
535: }
536: if (@nochanges > 0) {
537: $nochgresponse = &mt("The following automated enrollment parameters remain unchanged:<br/><ul>");
538: }
539: if (@changes > 0) {
540: my $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
541: if ($putreply !~ /^ok$/) {
542: $response = &mt("There was a problem processing your requested changes. The automated enrollment settings for this course have been left unchanged.<br/>");
543: } else {
544: foreach my $attr (@params) {
545: if (grep/^$attr$/,@changes) {
546: $chgresponse .= "<li>$$typeref{$attr} ".&mt("now set to \"").$newattr{$attr}."\".</li>";
547: } else {
548: $nochgresponse .= "<li>$$typeref{$attr} ".&mt("still set to \"").$currattr{$attr}."\".</li>";
549: }
550: }
551: if ($changecode || $changeowner) {
552: if ( $newattr{'courseowner'} eq '') {
553: $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/>");
554: } else {
555: if (@sections > 0) {
556: if ($changecode) {
557: foreach my $sec (@sections) {
558: if ($sec =~ m/^(.+):/) {
559: my $inst_course_id = $newattr{'coursecode'}.$1;
560: my $course_check = &Apache::lonnet::auto_validate_courseID($crs,$dom,$inst_course_id);
561: if ($course_check eq 'ok') {
562: my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$inst_course_id,$newattr{'courseowner'});
563: unless ($outcome eq 'ok') {
564: $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/>");
565: }
566: } else {
567: $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/>");
568: }
569: } else {
570: $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/>");
571: }
572: }
573: } elsif ($changeowner) {
574: foreach my $sec (@sections) {
575: if ($sec =~ m/^(.+):/) {
576: my $inst_course_id = $newattr{'coursecode'}.$1;
577: my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$inst_course_id,$newattr{'courseowner'});
578: unless ($outcome eq 'ok') {
579: $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/>");
580: }
581: } else {
582: $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/>");
583: }
584: }
585: }
586: } else {
587: $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/>";
588: }
589: if ( (@xlists > 0) && ($changeowner) ) {
590: foreach my $xlist (@xlists) {
591: if ($xlist =~ m/^(.+):/) {
592: my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$1,$newattr{'courseowner'});
593: unless ($outcome eq 'ok') {
594: $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/>");
595: }
596: }
597: }
598: }
599: }
600: }
601: }
602: } else {
603: foreach my $attr (@params) {
604: $nochgresponse .= "<li>$$typeref{$attr} ".&mt("still set to")." \"".$currattr{$attr}."\".</li>";
605: }
606: }
607:
608:
609: if (@changes > 0) {
610: $chgresponse .= "</ul><br/><br/>";
611: }
612: if (@nochanges > 0) {
613: $nochgresponse .= "</ul><br/><br/>";
614: }
615: unless ($warning eq '') {
616: $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;
617: }
618: if ($response eq '') {
619: $reply = $chgresponse.$nochgresponse.$warning;
620: } else {
621: $reply = $response;
622: }
623: &print_header($r,$tasklongref,$description);
624: $reply = "<h3>".&mt("Automated Enrollment Course Settings")."</h3><table><tr><td>".$reply."</td></tr></table>";
625: $r->print($reply);
626: &print_footer($r);
627: return;
628: }
629:
630: sub print_header {
631: my ($r,$tasklongref,$description,$javascriptref) = @_;
632: my %lt =&Apache::lonlocal::texthash(
633: 'vmcs' => 'View/Modify Course Settings',
634: 'chco' => 'Choose a course',
635: 'main' => 'Main Menu',
636: 'comg' => 'Course Manager',
637: );
638: my $action = "start";
639: if ( exists($ENV{'form.action'}) ) {
640: $action = $ENV{'form.action'};
641: }
642: if ( ($description eq '') || (!defined($description)) ) {
643: $description = $lt{'comg'};
644: }
645: my $page = '';
646: my $bodytag=&Apache::loncommon::bodytag($lt{'vmcs'});
647: if ($action eq 'start') {
648: $page = "<b>$lt{'chco'}</b>";
649: } else {
650: $page = '<a href="/adm/modifycourse">'.$lt{'chco'}.'</a>';
651: if ( $action eq 'process' ) {
652: my $course = $ENV{'form.course'};
653: $page .= "-> <a href=\"/adm/modifycourse?action=display&course=$course\">".$$tasklongref{'display'}."</a> -> <b>$$tasklongref{$action}</b> ";
654: } else {
655: $page .= " -> <b>".$$tasklongref{$action}."</b>";
656: }
657: }
658: $r->print("
659: <html>
660: <head>");
661: if ($action eq 'display') {
662: $r->print("
663: <script language=\"JavaScript\" type=\"text/javascript\">
664: $$javascriptref
665: </script>");
666: }
667: $r->print(<<ENDTHIS);
668: <title>The LearningOnline Network with CAPA</title>
669: </head>
670: $bodytag
671: <table width="100%" border="0" cellpadding="0" cellspacing="0">
672: <tr>
673: <td bgcolor="#CCCC99">
674: <font size="2"><a href="/adm/menu">$lt{'main'}</a> -> $page</font><br/>
675: </td>
676: <td align="right" bgcolor="#CCCC99" valign="top">
677: <font size="+1">$description </font>
678: </td>
679: </tr>
680: </table>
681: ENDTHIS
682: return;
683: }
684:
685: sub print_footer {
686: my $r = shift;
687: $r->print(<<ENDBASE);
688: <br/>
689: </body>
690: </html>
691: ENDBASE
692: return;
693: }
694:
695: sub check_course {
696: my ($dom,$course) = @_;
697: my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1);
698: foreach my $key (sort keys %courseIDs) {
699: if ($key =~ m/^($dom)_(\w+)$/) {
700: if ($2 eq $course) {
701: return 'ok';
702: }
703: }
704: }
705: return 'invalid course';
706: }
707:
708:
709: sub handler {
710: my $r = shift;
711: if ($r->header_only) {
712: &Apache::loncommon::content_type($r,'text/html');
713: $r->send_http_header;
714: return OK;
715: }
716:
717: if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
718: &Apache::loncommon::content_type($r,'text/html');
719: $r->send_http_header;
720:
721: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','course']);
722: my $dom = $ENV{'user.domain'};
723: my %longtype=&Apache::lonlocal::texthash(
724: 'authtype' => 'Default authentication method',
725: 'autharg' => 'Default authentication parameter',
726: 'autoadds' => 'Automated adds',
727: 'autodrops' => 'Automated drops',
728: 'autostart' => 'Date of first automated enrollment',
729: 'autoend' => 'Date of last automated enrollment',
730: 'default_enrollment_start_date' => 'Date of first student access',
731: 'default_enrollment_end_date' => 'Date of last student access',
732: 'coursecode' => 'Official course code',
733: 'courseowner' => "Username of course owner (\@$dom)",
734: 'notifylist' => 'Course Coordinators to be notified of enrollment changes',
735: 'sectionnums' => 'Course section number(:groupID)',
736: 'crosslistings' => 'Crosslisted class(:groupID)',
737: );
738:
739: my %tasklong = &Apache::lonlocal::texthash(
740: 'display' => 'View/modify settings',
741: 'process' => 'Results of changes',
742: );
743:
744: if ($ENV{'form.action'} eq 'process') {
745: &modify_course($r,\%tasklong,\%longtype);
746: } elsif ($ENV{'form.action'} eq 'display') {
747: &print_course_modification_page($r,\%tasklong,\%longtype);
748: } else {
749: &print_course_selection_page($r,\%tasklong);
750: }
751: } else {
752: $ENV{'user.error.msg'}=
753: "/adm/modifycourse:ccc:0:0:Cannot modify course settings";
754: return HTTP_NOT_ACCEPTABLE;
755: }
756: return OK;
757: }
758:
759: 1;
760: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>