Annotation of loncom/interface/lonmodifycourse.pm, revision 1.4
1.3 raeburn 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: #
1.1 raeburn 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(
1.2 raeburn 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",
1.1 raeburn 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);
1.2 raeburn 52: <form action="/adm/modifycourse" method="post" name="cmod">
1.3 raeburn 53: <h3>$lt{'csae'}</h3>
1.2 raeburn 54: <p>$lt{'unst'}
1.1 raeburn 55: </p><p>$lt{'chcs'}
1.2 raeburn 56: <br/>$lt{'eaen'}
57: </p><p>
1.1 raeburn 58: <b>$lt{'ccrs'}:</b>
59: <select name="course">
1.2 raeburn 60: <option value="0" />$lt{'psac'}
1.1 raeburn 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 = ();
1.3 raeburn 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:
1.1 raeburn 148: my @bgcolors=("#eeeeee","#cccccc");
149: my $ownertable;
1.2 raeburn 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:
1.1 raeburn 183: my %settings = &Apache::lonnet::dump('environment',$dom,$course);
1.2 raeburn 184: $enrollvar{'autharg'} = '';
185: $enrollvar{'authtype'} = '';
1.1 raeburn 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) ) {
1.2 raeburn 196: $enrollvar{$1} = $lt{'noen'};
1.1 raeburn 197: } else {
198: $enrollvar{$1} = localtime($settings{$item});
199: }
200: } else {
201: $enrollvar{$1} = $settings{$item};
202: }
203: }
204: }
205:
206: my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$course);
207: my @local_ccs = ();
208: my %cc_status = ();
209: my %pname = ();
210: my $active_cc;
211: foreach (@coursepersonnel) {
212: my @roleinfo = split/:/,$_;
213: if ( ($roleinfo[0] eq 'cc') && ($roleinfo[2] eq $dom) ) {
214: unless (grep/^$roleinfo[1]$/,@local_ccs) {
215: $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$course,'cc');
216: if ($active_cc eq 'ok') {
217: push @local_ccs, $roleinfo[1];
218: $pname{$roleinfo[1]} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
1.2 raeburn 219: $cc_status{$roleinfo[1]} = $lt{'actv'};
1.1 raeburn 220: }
221: }
222: }
223: }
224: unless ( (grep/^$enrollvar{'courseowner'}$/,@local_ccs) || ($enrollvar{'courseowner'} eq '') ) {
225: push @local_ccs, $enrollvar{'coursecode'};
1.2 raeburn 226: $pname{$enrollvar{'courseowner'}} = &Apache::loncommon::plainname($enrollvar{'courseowner'},$dom);
227: $active_cc = &LONCAPA::Enrollment::check_user_status($dom,$enrollvar{'coursecode'},$dom,$course,'cc');
1.1 raeburn 228: if ($active_cc eq 'ok') {
1.2 raeburn 229: $cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
1.1 raeburn 230: } else {
1.2 raeburn 231: $cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
1.1 raeburn 232: }
233: }
234: my $numlocalcc = @local_ccs;
1.2 raeburn 235: my $bodytag=&Apache::loncommon::bodytag(&mt("Modify Course Settings"));
236: my $helplink=&Apache::loncommon::help_open_topic('Modify_Course',&mt("Help on Modifying Courses"));
1.1 raeburn 237: my $defdom=$ENV{'request.role.domain'};
238: my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($defdom);
1.2 raeburn 239: my $curr_authtype = '';
240: my $curr_authfield = '';
241: if ($enrollvar{'authtype'} =~ /^krb/) {
242: $curr_authtype = 'krb';
243: } elsif ($enrollvar{'authtype'} eq 'internal' ) {
244: $curr_authtype = 'int';
245: } elsif ($enrollvar{'authtype'} eq 'localauth' ) {
246: $curr_authtype = 'loc';
247: }
248: unless ($curr_authtype eq '') {
249: $curr_authfield = $curr_authtype.'arg';
250: }
1.3 raeburn 251: $javascript_validations=&Apache::londropadd::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield);
1.2 raeburn 252: my %param = ( formname => 'document.cmod',
1.1 raeburn 253: kerb_def_dom => $krbdefdom,
1.2 raeburn 254: kerb_def_auth => $krbdef,
255: mode => 'modifycourse',
256: curr_authtype => $curr_authtype,
257: curr_autharg => $enrollvar{'autharg'}
1.1 raeburn 258: );
259: my $krbform = &Apache::loncommon::authform_kerberos(%param);
260: my $intform = &Apache::loncommon::authform_internal(%param);
261: my $locform = &Apache::loncommon::authform_local(%param);
262:
263: my $disp_table = qq|<table border="0" cellpadding="0" cellspacing="0">
264: <tr>
265: <td width="100%" bgcolor="#000000">
266: <table width="100%" border="0" cellpadding="1" cellspacing="0">
267: <tr>
268: <td width="100%" bgcolor="#000000">
269: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
270: <tr bgcolor="#CCCC99" align="center">
271: <td><b>$lt{'cset'}</b></td>
272: <td><b>$lt{'valu'}</b></td>
273: </tr>
274: |;
275: my $iter = 0;
276: foreach my $key (sort keys %enrollvar) {
277: my $colflag = $iter%2;
278: $disp_table .= "<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">
279: <td>$$typeref{$key}</td>
280: <td>$enrollvar{$key}</td>
281: </tr>";
282: $iter ++;
283: }
284: $disp_table .= "</table>
285: </td>
286: </tr>
287: </table>
288: </td>
289: </tr>
290: </table>";
291:
292: if ($numlocalcc == 0) {
1.2 raeburn 293: $ownertable = $lt{'nocc'};
1.1 raeburn 294: }
1.2 raeburn 295:
1.1 raeburn 296: if ($numlocalcc > 0) {
297: @local_ccs = sort @local_ccs;
298: $ownertable = qq(
299: <input type="hidden" name="numlocalcc" value="$numlocalcc" />
300: <table>
301: <tr>
302: <td>$lt{'tabl'} ($dom). $lt{'usrd'}
303: </td>
304: </tr>
305: <tr><td> </td></tr>
306: <tr>
307: <td>
308: <table border="0" cellpadding="0" cellspacing="0">
309: <tr>
310: <td width="100%" bgcolor="#000000">
311: <table width="100%" border="0" cellpadding="1" cellspacing="0">
312: <tr>
313: <td width="100%" bgcolor="#000000">
314: <table border="0" cellpadding="3" cellspacing="3" bgcolor="#FFFFFF">
315: <tr bgcolor="#CCCC99" align="center">
1.2 raeburn 316: <td><b>$lt{'ownr'}</b></td>
317: <td><b>$lt{'name'}</b></td>
318: <td><b>$lt{'unme'}</b></td>
319: <td><b>$lt{'stus'}</b></td>
1.1 raeburn 320: </tr>
321: );
322: for (my $i=0; $i<@local_ccs; $i++) {
323: my $colflag = $i%2;
324: $ownertable .= "<tr bgcolor=\"$bgcolors[$colflag]\" align=\"left\">";
325: if ($local_ccs[$i] eq $enrollvar{'courseowner'}) {
326: $ownertable .= "<td><input type=\"radio\" name=\"courseowner\" value=\"$i\" checked=\"true\"/></td>";
327: } else {
328: $ownertable .= "<td><input type=\"radio\" name=\"courseowner\" value=\"$i\" /></td>";
329: }
330: $ownertable .= "
331: <td>$pname{$local_ccs[$i]}</td>
332: <td><input type=\"hidden\" name=\"username_$i\" value=\"$local_ccs[$i]\" />$local_ccs[$i]</td>
1.2 raeburn 333: <td>$cc_status{$local_ccs[$i]} $lt{'ccor'}</td></tr>";
1.1 raeburn 334: }
335: $ownertable .= "</table>
336: </td>
337: </tr>
338: </table>
339: </td>
340: </tr>
341: </table>
342: </td>
343: </tr>
344: </table>";
345: }
346: &print_header($r,$tasklongref,$settings{'description'},\$javascript_validations);
347: $r->print(<<ENDDOCUMENT);
348: <form action="/adm/modifycourse" method="post" name="cmod">
1.3 raeburn 349: <h3>$lt{'aecs'}</h3>
1.1 raeburn 350: $lt{'cose'}<a href="/adm/populate">$lt{'aenm'}</a>$lt{'andb'}
351: <p>
352: <table width="100%" cellspacing="0" cellpadding="0">
353: <tr>
354: <td bgcolor="#CCCC99"> </td>
355: <td align="left" bgcolor="#CCCC99"><h3>$lt{'caes'}</h3></td>
356: </tr>
357: </table>
358: <p>
359: $lt{'cour'}
360: </p><p>
361: $disp_table
362: <br/<br/>
363: </p><p>
364:
365: <table width="100%" cellspacing="0" cellpadding="0">
366: <tr>
367: <td bgcolor="#CCCC99"> </td>
368: <td align="left" bgcolor="#CCCC99">
369: <h3>$lt{'mkch'}</h3>
370: </td>
371: </tr>
372: </table>
373: </p><p>
1.2 raeburn 374: <table width="100%" cellspacing="6" cellpadding="6">
375: <tr>
376: <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>
377: </tr>
1.1 raeburn 378: <tr>
379: <td width="50%" valign="top">
1.2 raeburn 380: <b>$lt{'ccod'}:</b>
1.1 raeburn 381: <input type="text" size="10" name="coursecode" value="$enrollvar{'coursecode'}"/><br/><br/>
382: $lt{'ccus'}
383: </td>
384: <td width="50%" valign="top" rowspan="2">
1.2 raeburn 385: <b>$lt{'cown'}:</b><br/><br/>
386: $ownertable
387: <br/><br/>
1.1 raeburn 388: $lt{'cous'}
389: </td>
390: </tr>
391: <tr>
392: <td width="50%" valign="top">
1.2 raeburn 393: <b>$lt{'deam'}:</b><br/><br/>
394: $krbform
395: <br/>
396: $intform
397: <br/>
398: $locform
399: <br/>
400: <br/>
1.1 raeburn 401: $lt{'deus'}.
402: </td>
403: <td width="50%"> </td>
404: </tr>
405: </table>
406: <br/><br/>
407: <table width="90%" cellpadding="5" cellspacing="0">
408: <tr>
409: <td align="right">
410: <input type="hidden" name="course" value="$course" />
411: <input type="hidden" name="action" value="process" />
412: <input type="button" onClick="verify_message(this.form)" value="$lt{'gobt'}" />
413: </td>
414: </tr>
415: </table>
416: </form>
417: <br/>
418: <br/>
419: ENDDOCUMENT
420: &print_footer($r);
421: }
422:
423: sub modify_course {
424: my ($r,$tasklongref,$typeref) = @_;
425: my $dom = $ENV{'user.domain'};
426: my $crs = $ENV{'form.course'};
1.3 raeburn 427:
428: unless ( &check_course($dom,$crs) eq 'ok' ) {
429: &print_header($r,$tasklongref);
430: my $reply = "<br/>".&mt("The LON-CAPA course selected was not a valid course for this domain");
431: $r->print($reply);
432: &print_footer($r);
433: return;
434: }
435:
1.2 raeburn 436: my %settings = &Apache::lonnet::get('environment',['internal.courseowner','internal.coursecode','internal.authtype','internal.autharg','internal.sectionnums','internal.crosslistings','description'],$dom,$crs);
1.1 raeburn 437: my %currattr = ();
438: my %newattr = ();
439: my %cenv = ();
440: my $response;
441: my $chgresponse;
442: my $nochgresponse;
443: my $warning;
444: my $reply;
445: my @changes = ();
446: my @nochanges = ();
447: my @sections = ();
448: my @xlists = ();
449: my $changecode = 0;
450: my $changeowner = 0;
451: unless ($settings{'internal.sectionnums'} eq'') {
452: if ($settings{'internal.sectionnums'} =~ m/,/) {
453: @sections = split/,/,$settings{'internal.sectionnums'};
454: } else {
455: $sections[0] = $settings{'internal.sectionnums'};
456: }
457: }
458: unless ($settings{'internal.crosslistings'} eq'') {
459: if ($settings{'internal.crosslistings'} =~ m/,/) {
460: @xlists = split/,/,$settings{'internal.crosslistings'};
461: } else {
462: $xlists[0] = $settings{'internal.crosslistings'};
463: }
464: }
465:
466: my @params = ('courseowner','coursecode','authtype','autharg');
467: foreach (@params) {
468: my $attr = 'internal.'.$_;
469: $currattr{$_} = $settings{$attr};
470: }
471:
472: my $description = $settings{'description'};
473: my %cenv = ();
474:
475: if ($ENV{'form.login'} eq 'krb') {
476: $newattr{'authtype'} = $ENV{'form.login'};
477: $newattr{'authtype'} .= $ENV{'form.krbver'};
478: $newattr{'autharg'} = $ENV{'form.krbarg'};
1.2 raeburn 479: $newattr{'autharg'} =~ tr/a-z/A-Z/;
1.1 raeburn 480: } elsif ($ENV{'form.login'} eq 'int') {
481: $newattr{'authtype'} ='internal';
482: if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
483: $newattr{'autharg'} = $ENV{'form.intarg'};
484: }
485: } elsif ($ENV{'form.login'} eq 'loc') {
486: $newattr{'authtype'} = 'localauth';
487: if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
488: $newattr{'autharg'} = $ENV{'form.locarg'};
489: }
490: }
491: if ( $newattr{'authtype'}=~ /^krb/) {
492: if ($newattr{'autharg'} eq '') {
1.2 raeburn 493: $warning = qq(<font color="red" size="+1">).
494: &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 495: }
496: }
497:
498: if ( exists($ENV{'form.courseowner'}) ) {
499: my $ownerparam = 'username_'.$ENV{'form.courseowner'};
500: if ( exists($ENV{"form.$ownerparam"}) ) {
501: $newattr{'courseowner'}=$ENV{"form.$ownerparam"};
502: unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
503: $changeowner = 1;
504: }
505: }
506: }
507:
508: if ( exists($ENV{'form.coursecode'}) ) {
509: $newattr{'coursecode'}=$ENV{'form.coursecode'};
510: unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
511: $changecode = 1;
512: }
513: }
514:
515: foreach (@params) {
516: if ($currattr{$_} eq $newattr{$_}) {
517: push @nochanges, $_;
518: } else {
519: my $attr = 'internal.'.$_;
520: $cenv{$attr} = $newattr{$_};
521: push @changes, $_;
522: }
523: }
524:
525: if (@changes > 0) {
1.2 raeburn 526: $chgresponse = &mt("The following automated enrollment parameters have been changed:<br/><ul>");
1.1 raeburn 527: }
528: if (@nochanges > 0) {
1.2 raeburn 529: $nochgresponse = &mt("The following automated enrollment parameters remain unchanged:<br/><ul>");
1.1 raeburn 530: }
531: if (@changes > 0) {
532: my $putreply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs);
533: if ($putreply !~ /^ok$/) {
1.2 raeburn 534: $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 535: } else {
536: foreach my $attr (@params) {
537: if (grep/^$attr$/,@changes) {
1.2 raeburn 538: $chgresponse .= "<li>$$typeref{$attr} ".&mt("now set to \"").$newattr{$attr}."\".</li>";
1.1 raeburn 539: } else {
1.2 raeburn 540: $nochgresponse .= "<li>$$typeref{$attr} ".&mt("still set to \"").$currattr{$attr}."\".</li>";
1.1 raeburn 541: }
542: }
543: if ($changecode || $changeowner) {
544: if ( $newattr{'courseowner'} eq '') {
1.2 raeburn 545: $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 546: } else {
547: if (@sections > 0) {
1.2 raeburn 548: if ($changecode) {
549: foreach my $sec (@sections) {
550: if ($sec =~ m/^(.+):/) {
551: my $course_id = $newattr{'coursecode'}.$1;
1.3 raeburn 552: my $course_check = &localenroll::validate_courseID($course_id);
1.1 raeburn 553: if ($course_check eq 'ok') {
1.3 raeburn 554: my $outcome = &localenroll::new_course($course_id,$newattr{'courseowner'});
1.1 raeburn 555: unless ($outcome eq 'ok') {
1.2 raeburn 556: $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 557: }
558: } else {
1.2 raeburn 559: $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 560: }
561: } else {
1.2 raeburn 562: $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 563: }
564: }
1.4 ! raeburn 565: } elsif ($changeowner) {
! 566: foreach my $sec (@sections) {
! 567: if ($sec =~ m/^(.+):/) {
! 568: my $course_id = $newattr{'coursecode'}.$1;
! 569: my $outcome = &localenroll::new_course($course_id,$newattr{'courseowner'});
! 570: unless ($outcome eq 'ok') {
! 571: $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/>");
! 572: }
! 573: } else {
! 574: $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/>");
! 575: }
! 576: }
! 577: }
1.1 raeburn 578: } else {
1.2 raeburn 579: $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 580: }
581: if ( (@xlists > 0) && ($changeowner) ) {
582: foreach my $xlist (@xlists) {
583: if ($xlist =~ m/^(.+):/) {
1.3 raeburn 584: my $outcome = &localenroll::new_course($1,$newattr{'courseowner'});
1.1 raeburn 585: unless ($outcome eq 'ok') {
1.2 raeburn 586: $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 587: }
588: }
589: }
590: }
591: }
592: }
593: }
1.2 raeburn 594: } else {
595: foreach my $attr (@params) {
596: $nochgresponse .= "<li>$$typeref{$attr} ".&mt("still set to \"").$currattr{$attr}."\".</li>";
597: }
1.1 raeburn 598: }
599:
1.2 raeburn 600:
1.1 raeburn 601: if (@changes > 0) {
602: $chgresponse .= "</ul><br/><br/>";
603: }
604: if (@nochanges > 0) {
605: $nochgresponse .= "</ul><br/><br/>";
606: }
607: unless ($warning eq '') {
1.2 raeburn 608: $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 609: }
610: if ($response eq '') {
611: $reply = $chgresponse.$nochgresponse.$warning;
612: } else {
613: $reply = $response;
614: }
615: &print_header($r,$tasklongref,$description);
1.3 raeburn 616: $reply = "<h3>".&mt("Automated Enrollment Course Settings")."</h3><table><tr><td>".$reply."</td></tr></table>";
617: $r->print($reply);
1.1 raeburn 618: &print_footer($r);
619: return;
620: }
621:
622: sub print_header {
623: my ($r,$tasklongref,$description,$javascriptref) = @_;
1.2 raeburn 624: my %lt =&Apache::lonlocal::texthash(
1.1 raeburn 625: 'vmcs' => 'View/Modify Course Settings',
626: 'chco' => 'Choose a course',
627: 'main' => 'Main Menu',
628: 'comg' => 'Course Manager',
629: );
630: my $action = "start";
631: if ( exists($ENV{'form.action'}) ) {
632: $action = $ENV{'form.action'};
633: }
634: if ( ($description eq '') || (!defined($description)) ) {
635: $description = $lt{'comg'};
636: }
637: my $page = '';
638: my $bodytag=&Apache::loncommon::bodytag($lt{'vmcs'});
639: if ($action eq 'start') {
640: $page = "<b>$lt{'chco'}</b>";
641: } else {
642: $page = '<a href="/adm/modifycourse">'.$lt{'chco'}.'</a>';
643: if ( $action eq 'process' ) {
644: my $course = $ENV{'form.course'};
645: $page .= "-> <a href=\"/adm/modifycourse?action=display&course=$course\">".$$tasklongref{'display'}."</a> -> <b>$$tasklongref{$action}</b> ";
646: } else {
647: $page .= " -> <b>".$$tasklongref{$action}."</b>";
648: }
649: }
650: $r->print("
651: <html>
652: <head>");
653: if ($action eq 'display') {
654: $r->print("
655: <script language=\"JavaScript\" type=\"text/javascript\">
656: $$javascriptref
657: </script>");
658: }
659: $r->print(<<ENDTHIS);
660: <title>The LearningOnline Network with CAPA</title>
661: </head>
662: $bodytag
663: <table width="100%" border="0" cellpadding="0" cellspacing="0">
664: <tr>
665: <td bgcolor="#CCCC99">
666: <font size="2"><a href="/adm/menu">$lt{'main'}</a> -> $page</font><br/>
667: </td>
668: <td align="right" bgcolor="#CCCC99" valign="top">
669: <font size="+1">$description </font>
670: </td>
671: </tr>
672: </table>
673: ENDTHIS
674: }
675:
676: sub print_footer {
677: my $r = shift;
678: $r->print(<<ENDBASE);
679: <br/>
680: </body>
681: </html>
682: ENDBASE
1.3 raeburn 683: }
684:
685: sub check_course {
686: my ($dom,$course) = @_;
687: my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1);
688: my @courses = ();
689: foreach my $key (sort keys %courseIDs) {
690: if ($key =~ m/^($dom)_(\w+)$/) {
691: push @courses, $2;
692: }
693: }
694: if (grep/^$course$/,@courses) {
695: return 'ok';
696: }
697: else {
698: return 'invalid course';
699: }
1.1 raeburn 700: }
701:
702:
703: sub handler {
704: my $r = shift;
705: if ($r->header_only) {
706: &Apache::loncommon::content_type($r,'text/html');
707: $r->send_http_header;
708: return OK;
709: }
710:
711: if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) {
712: &Apache::loncommon::content_type($r,'text/html');
713: $r->send_http_header;
714:
715: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','course']);
716: my $dom = $ENV{'user.domain'};
1.2 raeburn 717: my %longtype=&Apache::lonlocal::texthash(
1.1 raeburn 718: 'authtype' => 'Default authentication method',
719: 'autharg' => 'Default authentication parameter',
720: 'autoadds' => 'Automated adds',
721: 'autodrops' => 'Automated drops',
722: 'autostart' => 'Date of first enrollment',
723: 'autoend' => 'Date of last enrollment',
724: 'coursecode' => 'Official course code',
725: 'courseowner' => "Username of course owner (\@$dom)",
726: 'notifylist' => 'Course Coordinators to be notified of enrollment changes',
727: 'sectionnums' => 'Course section number(:groupID)',
728: 'crosslistings' => 'Crosslisted class(:groupID)',
729: );
730:
1.2 raeburn 731: my %tasklong = &Apache::lonlocal::texthash(
1.1 raeburn 732: 'display' => 'View/modify settings',
733: 'process' => 'Results of changes',
734: );
735:
736: if ($ENV{'form.action'} eq 'process') {
737: &modify_course($r,\%tasklong,\%longtype);
738: } elsif ($ENV{'form.action'} eq 'display') {
739: &print_course_modification_page($r,\%tasklong,\%longtype);
740: } else {
741: &print_course_selection_page($r,\%tasklong);
742: }
743: } else {
744: $ENV{'user.error.msg'}=
1.2 raeburn 745: "/adm/modifycourse:ccc:0:0:Cannot modify course settings";
1.1 raeburn 746: return HTTP_NOT_ACCEPTABLE;
747: }
748: return OK;
749: }
750:
751: 1;
752: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>