--- loncom/interface/lonmodifycourse.pm 2003/12/28 01:37:02 1.2 +++ loncom/interface/lonmodifycourse.pm 2004/06/29 14:56:32 1.10 @@ -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; @@ -28,7 +50,7 @@ sub print_course_selection_page { &print_header($r,$tasklongref); $r->print(< -

$lt{'csae'}

+

$lt{'csae'}

$lt{'unst'}

$lt{'chcs'}
$lt{'eaen'} @@ -78,7 +100,11 @@ 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); + } 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'}) ) { @@ -102,9 +128,28 @@ ENDBLOCK sub print_course_modification_page { my ($r,$tasklongref,$typeref) = @_; my %enrollvar = (); - my @bgcolors=("#eeeeee","#cccccc"); - my $course = $ENV{'form.course'}; + my $javascript_validations; + my $course = ''; my $dom = $ENV{'user.domain'}; + if ( defined($ENV{'form.course'}) ) { + $course = $ENV{'form.course'}; + } + my $ok_course = 'ok'; + if ( ($course == -1) || ($course == '-2') || ($course eq '') ) { + $ok_course = 'invalid'; + } else { + $ok_course = &check_course($dom,$course); + } + + unless ($ok_course eq 'ok') { + &print_header($r,$tasklongref,'',\$javascript_validations); + my $reply = "
".&mt("The LON-CAPA course selected was not a valid course for this domain"); + $r->print($reply); + &print_footer($r); + return; + } + + my @bgcolors=("#eeeeee","#cccccc"); my $ownertable; my %lt=&Apache::lonlocal::texthash( 'actv' => "Active", @@ -156,9 +201,17 @@ all settings except course code, course } else { $enrollvar{$1} = localtime($settings{$item}); } - } else { + } elsif ($1 eq "courseowner" || $1 eq "authtype" || $1 eq "autharg" || $1 eq "sectionnums" || $1 eq "coursecode" || $1 eq "crosslistings") { $enrollvar{$1} = $settings{$item}; } + } elsif ($item =~ m/^default_enrollment_(start|end)_date$/) { + if ( ($1 eq 'end') && ($settings{$item} == 0) ) { + $enrollvar{$item} = $lt{'noen'}; + } elsif ( ($1 eq 'start') && ($settings{$item} eq '') ) { + $enrollvar{$item} = 'When enrolled'; + } else { + $enrollvar{$item} = localtime($settings{$item}); + } } } @@ -181,7 +234,7 @@ all settings except course code, course } } unless ( (grep/^$enrollvar{'courseowner'}$/,@local_ccs) || ($enrollvar{'courseowner'} eq '') ) { - push @local_ccs, $enrollvar{'coursecode'}; + 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') { @@ -207,7 +260,7 @@ all settings except course code, course unless ($curr_authtype eq '') { $curr_authfield = $curr_authtype.'arg'; } - my $javascript_validations=&Apache::londropadd::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield); + $javascript_validations=&Apache::londropadd::javascript_validations('modifycourse',$krbdefdom,$curr_authtype,$curr_authfield); my %param = ( formname => 'document.cmod', kerb_def_dom => $krbdefdom, kerb_def_auth => $krbdef, @@ -238,7 +291,7 @@ all settings except course code, course $$typeref{$key} $enrollvar{$key} "; - $iter ++; + $iter ++; } $disp_table .= " @@ -305,7 +358,7 @@ all settings except course code, course &print_header($r,$tasklongref,$settings{'description'},\$javascript_validations); $r->print(< -

$lt{'aecs'}

+

$lt{'aecs'}

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

@@ -377,12 +430,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'}; + 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 = (); @@ -459,6 +521,8 @@ sub modify_course { $newattr{'coursecode'}=$ENV{'form.coursecode'}; unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) { $changecode = 1; + my $courseid_entry = &Apache::lonnet::escape($dom.'_'.$crs).'='.&Apache::lonnet::escape($description).'='.&Apache::lonnet::escape($ENV{'form.coursecode'}); + &Apache::lonnet::courseidput($dom,$courseid_entry,&Apache::lonnet::homeserver($crs,$dom)); } } @@ -498,12 +562,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 +576,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 +607,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 +627,8 @@ sub modify_course { $reply = $response; } &print_header($r,$tasklongref,$description); - $r->print("
    $reply
    ".$reply."
    "; + $r->print($reply); &print_footer($r); return; } @@ -611,15 +685,30 @@ $bodytag ENDTHIS + return; } sub print_footer { - my $r = shift; - $r->print(<print(< ENDBASE + return; +} + +sub check_course { + my ($dom,$course) = @_; + my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1); + foreach my $key (sort keys %courseIDs) { + if ($key =~ m/^($dom)_(\w+)$/) { + if ($2 eq $course) { + return 'ok'; + } + } + } + return 'invalid course'; } @@ -642,8 +731,10 @@ sub handler { 'autharg' => 'Default authentication parameter', 'autoadds' => 'Automated adds', 'autodrops' => 'Automated drops', - 'autostart' => 'Date of first enrollment', - 'autoend' => 'Date of last enrollment', + 'autostart' => 'Date of first automated enrollment', + 'autoend' => 'Date of last automated enrollment', + 'default_enrollment_start_date' => 'Date of first student access', + 'default_enrollment_end_date' => 'Date of last student access', 'coursecode' => 'Official course code', 'courseowner' => "Username of course owner (\@$dom)", 'notifylist' => 'Course Coordinators to be notified of enrollment changes',