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