--- loncom/interface/lonmodifycourse.pm 2003/12/28 01:37:02 1.2 +++ loncom/interface/lonmodifycourse.pm 2005/04/12 00:20:00 1.17 @@ -1,3 +1,25 @@ +# Copyright Michigan State University Board of Trustees +# +# This file is part of the LearningOnline Network with CAPA (LON-CAPA). +# +# LON-CAPA is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# LON-CAPA is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with LON-CAPA; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# /home/httpd/html/adm/gpl.txt +# +# http://www.lon-capa.org/ +# package Apache::lonmodifycourse; use strict; @@ -8,11 +30,10 @@ use Apache::lonlocal; use Apache::londropadd; use LONCAPA::Enrollment; use lib '/home/httpd/lib/perl'; -use localenroll; 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.", @@ -24,11 +45,11 @@ sub print_course_selection_page { ); # Determine the courses - my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1); + my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1,'.','.','.'); &print_header($r,$tasklongref); $r->print(< -

$lt{'csae'}

+

$lt{'csae'}

$lt{'unst'}

$lt{'chcs'}
$lt{'eaen'} @@ -44,23 +65,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; @@ -78,11 +95,22 @@ ENDBLOCK unless ($code =~m/^___\d+$/) { $showcode = $code; } if ($item =~ m/^($dom)_(\w+)$/) { $crs = $2; - $description = $courseIDs{$item}; + if ($courseIDs{$item} =~ /^([^:]*):([^:]*):([^:]*)/) { + $description = &Apache::lonnet::unescape($1); + $owner = &Apache::lonnet::unescape($3); + } elsif ($courseIDs{$item} =~ /^([^:]*):([^:]*)$/) { + $description = &Apache::lonnet::unescape($1); + } else { + $description = &Apache::lonnet::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'}; + if ($owner eq '') { + my %settings = &Apache::lonnet::get('environment',['internal.courseowner'],$dom,$crs); + if ( defined($settings{'internal.courseowner'}) ) { + $owner = $settings{'internal.courseowner'}; + } + } + unless ($owner eq '') { $ownername = &Apache::loncommon::plainname($owner,$dom); } $r->print("

$lt{'aecs'}

+

$lt{'aecs'}

$lt{'cose'}$lt{'aenm'}$lt{'andb'}

@@ -377,12 +431,21 @@ $disp_table
ENDDOCUMENT &print_footer($r); + return; } 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"); + $r->print($reply); + &print_footer($r); + return; + } + my %settings = &Apache::lonnet::get('environment',['internal.courseowner','internal.coursecode','internal.authtype','internal.autharg','internal.sectionnums','internal.crosslistings','description'],$dom,$crs); my %currattr = (); my %newattr = (); @@ -422,20 +485,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/) { @@ -445,22 +507,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 = &Apache::lonnet::escape($dom.'_'.$crs).'='.&Apache::lonnet::escape($description).':'.&Apache::lonnet::escape($env{'form.coursecode'}).':'.&Apache::lonnet::escape($env{'form.courseowner'}); + &Apache::lonnet::courseidput($dom,$courseid_entry,&Apache::lonnet::homeserver($crs,$dom)); + } foreach (@params) { if ($currattr{$_} eq $newattr{$_}) { @@ -498,12 +561,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); - my $course_check = 'ok'; - if ($course_check eq 'ok') { -# my $outcome = &localenroll::new_course($course_id,$newattr{'courseowner'}); - my $outcome = 'ok'; + 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.
"); } @@ -514,15 +575,26 @@ sub modify_course { $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.
"); } } - } + } elsif ($changeowner) { + foreach my $sec (@sections) { + if ($sec =~ m/^(.+):/) { + 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.
"); + } + } else { + $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.
"); + } + } + } } else { $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'}."
"; } if ( (@xlists > 0) && ($changeowner) ) { foreach my $xlist (@xlists) { if ($xlist =~ m/^(.+):/) { -# my $outcome = &localenroll::new_course($1,$newattr{'courseowner'}); - my $outcome = 'ok'; + 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.
"); } @@ -534,7 +606,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}."\".
  • "; } } @@ -554,7 +626,8 @@ sub modify_course { $reply = $response; } &print_header($r,$tasklongref,$description); - $r->print("
    $reply
    ".$reply."
    "; + $r->print($reply); &print_footer($r); return; } @@ -568,8 +641,8 @@ sub print_header { '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'}; @@ -581,15 +654,17 @@ sub print_header { } 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}.""; } } + my $html=&Apache::lonxml::xmlbegin(); $r->print(" - -"); +$html + +"); if ($action eq 'display') { $r->print("