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