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