--- loncom/interface/lonmodifycourse.pm 2003/12/31 18:32:23 1.6
+++ loncom/interface/lonmodifycourse.pm 2006/07/18 21:52:01 1.27
@@ -1,3 +1,8 @@
+# The LearningOnline Network with CAPA
+# automated enrollment course setup handler
+#
+# $Id: lonmodifycourse.pm,v 1.27 2006/07/18 21:52:01 albertel Exp $
+#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -30,11 +35,11 @@ use Apache::lonlocal;
use Apache::londropadd;
use LONCAPA::Enrollment;
use lib '/home/httpd/lib/perl';
-use localenroll;
+use LONCAPA;
sub print_course_selection_page {
my ($r,$tasklongref) = @_;
- my $dom = $ENV{'user.domain'};
+ my $dom = $env{'request.role.domain'};
my %lt=&Apache::lonlocal::texthash(
'csae' => "Course settings for automated enrollment",
'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,7 +51,7 @@ sub print_course_selection_page {
);
# Determine the courses
- my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1);
+ my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.',undef,undef,'.');
&print_header($r,$tasklongref);
$r->print(<
@@ -57,8 +62,8 @@ sub print_course_selection_page {
$lt{'ccrs'}:
- $lt{'psac'}
- ---------------------------------------------------
+ $lt{'psac'}
+ ---------------------------------------------------
ENDBLOCK
my $iter = 0;
my @codes = ();
@@ -66,23 +71,19 @@ ENDBLOCK
foreach my $key (sort keys %courseIDs) {
# Get current code
my $crs;
- my $currcode;
- if ($key =~ m/^($dom)_(\w+)$/) {
+ my ($description,$currcode,$owner);
+ if ($courseIDs{$key} =~ m/^([^:]*):([^:]+)/ ) {
+ $currcode = $2;
+ } elsif ($key =~ m/^($dom)_(\w+)$/) {
$crs = $2;
my %settings = &Apache::lonnet::get('environment',['internal.coursecode'],$dom,$crs);
if (defined($settings{'internal.coursecode'}) ) {
$currcode = $settings{'internal.coursecode'};
- if ($currcode eq '') {
- $currcode = "___".$iter;
- $iter ++;
- }
- } else {
- $currcode = "___".$iter;
- $iter ++;
}
- } else {
+ }
+ if ($currcode eq '') {
$currcode = "___".$iter;
- $iter ++;
+ $iter ++;
}
unless (grep/^$currcode$/,@codes) {
push @codes,$currcode;
@@ -100,14 +101,37 @@ ENDBLOCK
unless ($code =~m/^___\d+$/) { $showcode = $code; }
if ($item =~ m/^($dom)_(\w+)$/) {
$crs = $2;
- $description = $courseIDs{$item};
+ if ($courseIDs{$item} =~ /^([^:]*):([^:]*):([^:]*)/) {
+ $description = &unescape($1);
+ $owner = &unescape($3);
+ if (($owner ne '') && ($owner !~ /^([^:]+):([^:]+)$/)) {
+ $owner = $owner.':'.$dom;
+ }
+ } elsif ($courseIDs{$item} =~ /^([^:]*):([^:]*)$/) {
+ $description = &unescape($1);
+ } else {
+ $description = &unescape($courseIDs{$item});
+ }
# Get course owner
- my %settings = &Apache::lonnet::get('environment',['internal.courseowner'],$dom,$crs);
- if ( defined($settings{'internal.courseowner'}) ) {
- $owner = $settings{'internal.courseowner'};
- $ownername = &Apache::loncommon::plainname($owner,$dom);
+ if ($owner eq '') {
+ my %settings = &Apache::lonnet::get('environment',['internal.courseowner'],$dom,$crs);
+ if ( defined($settings{'internal.courseowner'}) ) {
+ $owner = $settings{'internal.courseowner'};
+ }
}
- $r->print("$showcode -- $description ---------- $ownername");
+ unless ($owner eq '') {
+ my ($owneruname,$ownerdom);
+ if ($owner =~ /^([^:]+):([^:]+)$/) {
+ $owneruname = $1;
+ $ownerdom = $2;
+ } else {
+ $owneruname = $owner;
+ $ownerdom = $dom;
+ }
+ $ownername = &Apache::loncommon::plainname($owneruname,
+ $ownerdom);
+ }
+ $r->print(" $showcode -- $description ---------- $ownername ");
}
}
}
@@ -126,9 +150,9 @@ sub print_course_modification_page {
my %enrollvar = ();
my $javascript_validations;
my $course = '';
- my $dom = $ENV{'user.domain'};
- if ( defined($ENV{'form.course'}) ) {
- $course = $ENV{'form.course'};
+ my $dom = $env{'request.role.domain'};
+ if ( defined($env{'form.course'}) ) {
+ $course = $env{'form.course'};
}
my $ok_course = 'ok';
if ( ($course == -1) || ($course == '-2') || ($course eq '') ) {
@@ -154,7 +178,7 @@ sub print_course_modification_page {
'noen' => "No end date",
'ownr' => "Owner",
'name' => "Name",
- 'unme' => "Username",
+ 'unme' => "Username:Domain",
'stus' => "Status",
'aecs' => "Automated Enrollment Course Settings",
'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 ",
@@ -184,21 +208,45 @@ all settings except course code, course
$enrollvar{'autharg'} = '';
$enrollvar{'authtype'} = '';
foreach my $item (keys %settings) {
- if ($item =~ m/^internal\.(.+)$/) {
- if ( ($1 eq "autoadds") || ($1 eq "autodrops") ) {
+ if ($item =~ m/^internal\.(.+)$/) {
+ my $type = $1;
+
+ if ( ($type eq "autoadds") || ($type eq "autodrops") ) {
if ($settings{$item} == 1) {
- $enrollvar{$1} = "ON";
+ $enrollvar{$type} = "ON";
} else {
- $enrollvar{$1} = "OFF";
+ $enrollvar{$type} = "OFF";
}
- } elsif ( ($1 eq "autostart") || ($1 eq "autoend") ) {
- if ( ($1 eq "autoend") && ($settings{$item} == 0) ) {
- $enrollvar{$1} = $lt{'noen'};
+ } elsif ( ($type eq "autostart") || ($type eq "autoend") ) {
+ if ( ($type eq "autoend") && ($settings{$item} == 0) ) {
+ $enrollvar{$type} = $lt{'noen'};
} else {
- $enrollvar{$1} = localtime($settings{$item});
+ $enrollvar{$type} = localtime($settings{$item});
}
+ } elsif ($type eq "sectionums") {
+ $enrollvar{$type} = $settings{$item};
+ $enrollvar{$type} =~ s/,/, /g;
+ } elsif ($type eq "authtype"
+ || $type eq "autharg" || $type eq "coursecode"
+ || $type eq "crosslistings") {
+ $enrollvar{$type} = $settings{$item};
+ } elsif ($type eq 'courseowner') {
+ if ($settings{$item} =~ /^[^:]+:[^:]+$/) {
+ $enrollvar{$type} = $settings{$item};
+ } else {
+ if ($settings{$item} ne '') {
+ $enrollvar{$type} = $settings{$item}.':'.$dom;
+ }
+ }
+ }
+ } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) {
+ my $type = $1;
+ if ( ($type eq 'end') && ($settings{$item} == 0) ) {
+ $enrollvar{$item} = $lt{'noen'};
+ } elsif ( ($type eq 'start') && ($settings{$item} eq '') ) {
+ $enrollvar{$item} = 'When enrolled';
} else {
- $enrollvar{$1} = $settings{$item};
+ $enrollvar{$item} = localtime($settings{$item});
}
}
}
@@ -208,34 +256,41 @@ all settings except course code, course
my %cc_status = ();
my %pname = ();
my $active_cc;
- foreach (@coursepersonnel) {
- my @roleinfo = split/:/,$_;
- if ( ($roleinfo[0] eq 'cc') && ($roleinfo[2] eq $dom) ) {
- unless (grep/^$roleinfo[1]$/,@local_ccs) {
- $active_cc = &LONCAPA::Enrollment::check_user_status($roleinfo[2],$roleinfo[1],$dom,$course,'cc');
- if ($active_cc eq 'ok') {
- push @local_ccs, $roleinfo[1];
- $pname{$roleinfo[1]} = &Apache::loncommon::plainname($roleinfo[1],$roleinfo[2]);
- $cc_status{$roleinfo[1]} = $lt{'actv'};
+ foreach my $person (@coursepersonnel) {
+ my ($role,$user) = split(/:/,$person,2);
+ $user =~ s/:$//;
+ if (($role eq 'cc') && ($user ne '')) {
+ if (!grep(/^\Q$user\E$/,@local_ccs)) {
+ my ($ccname,$ccdom) = split(/:/,$user);
+ $active_cc =
+ &Apache::loncommon::check_user_status($ccdom,$ccname,$dom,
+ $course,'cc');
+ if ($active_cc eq 'active') {
+ push(@local_ccs,$user);
+ $pname{$user} = &Apache::loncommon::plainname($ccname,$ccdom);
+ $cc_status{$user} = $lt{'actv'};
}
}
}
}
- unless ( (grep/^$enrollvar{'courseowner'}$/,@local_ccs) || ($enrollvar{'courseowner'} eq '') ) {
- push @local_ccs, $enrollvar{'courseowner'};
- $pname{$enrollvar{'courseowner'}} = &Apache::loncommon::plainname($enrollvar{'courseowner'},$dom);
- $active_cc = &LONCAPA::Enrollment::check_user_status($dom,$enrollvar{'coursecode'},$dom,$course,'cc');
- if ($active_cc eq 'ok') {
+ if ( (!grep(/^$enrollvar{'courseowner'}$/,@local_ccs)) &&
+ ($enrollvar{'courseowner'} ne '') ) {
+ my ($owneruname,$ownerdom) = split(/:/,$enrollvar{'courseowner'});
+ push(@local_ccs,$enrollvar{'courseowner'});
+ $pname{$enrollvar{'courseowner'}} =
+ &Apache::loncommon::plainname($owneruname,$ownerdom);
+ $active_cc = &Apache::loncommon::check_user_status($ownerdom,$owneruname,
+ $dom,$course,'cc');
+ if ($active_cc eq 'active') {
$cc_status{$enrollvar{'courseowner'}} = $lt{'actv'};
} else {
$cc_status{$enrollvar{'courseowner'}} = $lt{'inac'};
}
}
my $numlocalcc = @local_ccs;
- my $bodytag=&Apache::loncommon::bodytag(&mt("Modify Course Settings"));
+
my $helplink=&Apache::loncommon::help_open_topic('Modify_Course',&mt("Help on Modifying Courses"));
- my $defdom=$ENV{'request.role.domain'};
- my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($defdom);
+ my ($krbdef,$krbdefdom)=&Apache::loncommon::get_kerberos_defaults($dom);
my $curr_authtype = '';
my $curr_authfield = '';
if ($enrollvar{'authtype'} =~ /^krb/) {
@@ -323,13 +378,13 @@ all settings except course code, course
my $colflag = $i%2;
$ownertable .= "";
if ($local_ccs[$i] eq $enrollvar{'courseowner'}) {
- $ownertable .= " ";
+ $ownertable .= " ";
} else {
- $ownertable .= " ";
+ $ownertable .= " ";
}
$ownertable .= "
$pname{$local_ccs[$i]}
- $local_ccs[$i]
+ $local_ccs[$i]
$cc_status{$local_ccs[$i]} $lt{'ccor'} ";
}
$ownertable .= "
@@ -423,9 +478,8 @@ ENDDOCUMENT
sub modify_course {
my ($r,$tasklongref,$typeref) = @_;
- my $dom = $ENV{'user.domain'};
- my $crs = $ENV{'form.course'};
-
+ my $dom = $env{'user.domain'};
+ my $crs = $env{'form.course'};
unless ( &check_course($dom,$crs) eq 'ok' ) {
&print_header($r,$tasklongref);
my $reply = " ".&mt("The LON-CAPA course selected was not a valid course for this domain");
@@ -473,20 +527,19 @@ sub modify_course {
my $description = $settings{'description'};
my %cenv = ();
- if ($ENV{'form.login'} eq 'krb') {
- $newattr{'authtype'} = $ENV{'form.login'};
- $newattr{'authtype'} .= $ENV{'form.krbver'};
- $newattr{'autharg'} = $ENV{'form.krbarg'};
- $newattr{'autharg'} =~ tr/a-z/A-Z/;
- } elsif ($ENV{'form.login'} eq 'int') {
+ if ($env{'form.login'} eq 'krb') {
+ $newattr{'authtype'} = $env{'form.login'};
+ $newattr{'authtype'} .= $env{'form.krbver'};
+ $newattr{'autharg'} = $env{'form.krbarg'};
+ } elsif ($env{'form.login'} eq 'int') {
$newattr{'authtype'} ='internal';
- if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) {
- $newattr{'autharg'} = $ENV{'form.intarg'};
+ if ((defined($env{'form.intarg'})) && ($env{'form.intarg'})) {
+ $newattr{'autharg'} = $env{'form.intarg'};
}
- } elsif ($ENV{'form.login'} eq 'loc') {
+ } elsif ($env{'form.login'} eq 'loc') {
$newattr{'authtype'} = 'localauth';
- if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) {
- $newattr{'autharg'} = $ENV{'form.locarg'};
+ if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
+ $newattr{'autharg'} = $env{'form.locarg'};
}
}
if ( $newattr{'authtype'}=~ /^krb/) {
@@ -496,22 +549,23 @@ sub modify_course {
}
}
- if ( exists($ENV{'form.courseowner'}) ) {
- my $ownerparam = 'username_'.$ENV{'form.courseowner'};
- if ( exists($ENV{"form.$ownerparam"}) ) {
- $newattr{'courseowner'}=$ENV{"form.$ownerparam"};
- unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
- $changeowner = 1;
- }
+ if ( exists($env{'form.courseowner'}) ) {
+ $newattr{'courseowner'}=$env{'form.courseowner'};
+ unless ( $newattr{'courseowner'} eq $currattr{'courseowner'} ) {
+ $changeowner = 1;
}
}
- if ( exists($ENV{'form.coursecode'}) ) {
- $newattr{'coursecode'}=$ENV{'form.coursecode'};
+ if ( exists($env{'form.coursecode'}) ) {
+ $newattr{'coursecode'}=$env{'form.coursecode'};
unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) {
$changecode = 1;
}
}
+ if ($changeowner == 1 || $changecode == 1) {
+ my $courseid_entry = &escape($dom.'_'.$crs).'='.&escape($description).':'.&escape($env{'form.coursecode'}).':'.&escape($env{'form.courseowner'});
+ &Apache::lonnet::courseidput($dom,$courseid_entry,&Apache::lonnet::homeserver($crs,$dom));
+ }
foreach (@params) {
if ($currattr{$_} eq $newattr{$_}) {
@@ -549,10 +603,10 @@ sub modify_course {
if ($changecode) {
foreach my $sec (@sections) {
if ($sec =~ m/^(.+):/) {
- my $course_id = $newattr{'coursecode'}.$1;
- my $course_check = &localenroll::validate_courseID($course_id);
- if ($course_check eq 'ok') {
- my $outcome = &localenroll::new_course($course_id,$newattr{'courseowner'});
+ my $inst_course_id = $newattr{'coursecode'}.$1;
+ my $course_check = &Apache::lonnet::auto_validate_courseID($crs,$dom,$inst_course_id);
+ if ($course_check eq 'ok') {
+ my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$inst_course_id,$newattr{'courseowner'});
unless ($outcome eq 'ok') {
$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. ");
}
@@ -566,8 +620,8 @@ sub modify_course {
} elsif ($changeowner) {
foreach my $sec (@sections) {
if ($sec =~ m/^(.+):/) {
- my $course_id = $newattr{'coursecode'}.$1;
- my $outcome = &localenroll::new_course($course_id,$newattr{'courseowner'});
+ my $inst_course_id = $newattr{'coursecode'}.$1;
+ my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$inst_course_id,$newattr{'courseowner'});
unless ($outcome eq 'ok') {
$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. ");
}
@@ -582,7 +636,7 @@ sub modify_course {
if ( (@xlists > 0) && ($changeowner) ) {
foreach my $xlist (@xlists) {
if ($xlist =~ m/^(.+):/) {
- my $outcome = &localenroll::new_course($1,$newattr{'courseowner'});
+ my $outcome = &Apache::lonnet::auto_new_course($crs,$dom,$1,$newattr{'courseowner'});
unless ($outcome eq 'ok') {
$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. ");
}
@@ -594,7 +648,7 @@ sub modify_course {
}
} else {
foreach my $attr (@params) {
- $nochgresponse .= "$$typeref{$attr} ".&mt("still set to \"").$currattr{$attr}."\". ";
+ $nochgresponse .= "$$typeref{$attr} ".&mt("still set to")." \"".$currattr{$attr}."\". ";
}
}
@@ -623,44 +677,40 @@ sub modify_course {
sub print_header {
my ($r,$tasklongref,$description,$javascriptref) = @_;
my %lt =&Apache::lonlocal::texthash(
- 'vmcs' => 'View/Modify Course Settings',
'chco' => 'Choose a course',
'main' => 'Main Menu',
'comg' => 'Course Manager',
);
my $action = "start";
- if ( exists($ENV{'form.action'}) ) {
- $action = $ENV{'form.action'};
+ if ( exists($env{'form.action'}) ) {
+ $action = $env{'form.action'};
}
if ( ($description eq '') || (!defined($description)) ) {
$description = $lt{'comg'};
}
my $page = '';
- my $bodytag=&Apache::loncommon::bodytag($lt{'vmcs'});
+
if ($action eq 'start') {
$page = "$lt{'chco'} ";
} else {
$page = ''.$lt{'chco'}.' ';
if ( $action eq 'process' ) {
- my $course = $ENV{'form.course'};
+ my $course = $env{'form.course'};
$page .= "-> ".$$tasklongref{'display'}." -> $$tasklongref{$action} ";
} else {
$page .= " -> ".$$tasklongref{$action}." ";
}
}
- $r->print("
-
-");
+
+ my $js;
if ($action eq 'display') {
- $r->print("
-");
+ $js = '';
}
+ $r->print(&Apache::loncommon::start_page('View/Modify Course Settings',
+ $js));
$r->print(<The LearningOnline Network with CAPA
-
-$bodytag
@@ -676,18 +726,14 @@ ENDTHIS
}
sub print_footer {
- my $r = shift;
- $r->print(<
-
-