package Apache::lonmodifycourse; use strict; use Apache::Constants qw(:common :http); use Apache::lonnet; use Apache::loncommon; 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 %lt=&Apache::lonlocal::texthash( 'incs' => "Internal course settings", 'stat' => "Although the majority of course settings for LON-CAPA courses may be modified by a Course Coordinator, there are a small number of settings which may only be modified by a Domain Coordinator. These particular course parameters control automated student enrollment in LON-CAPA courses based on classlist data available from your institution's student information system.", 'chcs' => "Once you have chosen the course for which you wish to view/modify internal settings, click 'Go' to proceed", 'ccrs' => "Choose a course", 'gobt' => "Go" ); # Determine the courses my %courseIDs = &Apache::lonnet::courseiddump($dom,'.',1); &print_header($r,$tasklongref); $r->print(<

$lt{'incs'}

$lt{'stat'}

$lt{'chcs'}

$lt{'ccrs'}:  

"); &print_footer($r); return; } sub print_course_modification_page { my ($r,$tasklongref,$typeref) = @_; my %enrollvar = (); my @bgcolors=("#eeeeee","#cccccc"); my $course = $ENV{'form.course'}; my $dom = $ENV{'user.domain'}; my $ownertable; my %settings = &Apache::lonnet::dump('environment',$dom,$course); foreach my $item (keys %settings) { if ($item =~ m/^internal\.(.+)$/) { if ( ($1 eq "autoadds") || ($1 eq "autodrops") ) { if ($settings{$item} == 1) { $enrollvar{$1} = "ON"; } else { $enrollvar{$1} = "OFF"; } } elsif ( ($1 eq "autostart") || ($1 eq "autoend") ) { if ( ($1 eq "autoend") && ($settings{$item} == 0) ) { $enrollvar{$1} = "No end date"; } else { $enrollvar{$1} = localtime($settings{$item}); } } else { $enrollvar{$1} = $settings{$item}; } } } my @coursepersonnel = &Apache::lonnet::getkeys('nohist_userroles',$dom,$course); my @local_ccs = (); 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]} = 'Active'; } } } } unless ( (grep/^$enrollvar{'courseowner'}$/,@local_ccs) || ($enrollvar{'courseowner'} eq '') ) { push @local_ccs, $enrollvar{'coursecode'}; my ($puname,$pdom) = split/\@/,$enrollvar{'courseowner'}; $pname{$enrollvar{'courseowner'}} = &Apache::loncommon::plainname($puname,$pdom); $active_cc = &LONCAPA::Enrollment::check_user_status($pdom,$enrollvar{'coursecode'},$dom,$course,'cc'); if ($active_cc eq 'ok') { $cc_status{$enrollvar{'courseowner'}} = 'Active'; } else { $cc_status{$enrollvar{'courseowner'}} = 'Inactive'; } } my $numlocalcc = @local_ccs; my $bodytag=&Apache::loncommon::bodytag('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 $javascript_validations=&Apache::londropadd::javascript_validations('createcourse',$krbdefdom); my %param = ( formname => 'document.cmods', kerb_def_dom => $krbdefdom, kerb_def_auth => $krbdef ); my $selscript=&Apache::loncommon::studentbrowser_javascript(); my $sellink=&Apache::loncommon::selectstudent_link ('cmod','crsown','ccdomain'); my $krbform = &Apache::loncommon::authform_kerberos(%param); my $intform = &Apache::loncommon::authform_internal(%param); my $locform = &Apache::loncommon::authform_local(%param); my %lt=&Apache::lonlocal::texthash( '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 ", 'aenm' => "Automated Enrollment Manager", 'andb' => " and (b) settings that may only be modified by a Domain Coordinator via this page.", 'caes' => 'Current automated enrollment settings', 'cour' => "Course settings that control automated enrollment in this LON-CAPA course are currently:", 'cset' => "Course setting", 'valu' => "Current value", 'ccus' => "A course coordinator can use the 'Automated Enrollment Manager' to change 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).", 'mkch' => "Make changes to course settings set by Domain Coordinator", 'ccod' => "Course Code", '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.", 'cown' => "Course Owner", '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.", 'tabl' => 'The table below contains a list of active course coordinators in this course, who are from this domain', 'usrd' => 'Use the radio buttons to select a different course owner.', 'deam' => "Default Authentication method", '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.", 'gobt' => "Modify settings", ); my $disp_table = qq|
|; my $iter = 0; foreach my $key (sort keys %enrollvar) { my $colflag = $iter%2; $disp_table .= ""; $iter ++; } $disp_table .= "
$lt{'cset'} $lt{'valu'}
$$typeref{$key} $enrollvar{$key}
"; if ($numlocalcc == 0) { $ownertable = "No course coordinators"; } if ($numlocalcc > 0) { @local_ccs = sort @local_ccs; $ownertable = qq(
$lt{'tabl'} ($dom). $lt{'usrd'}
 
); for (my $i=0; $i<@local_ccs; $i++) { my $colflag = $i%2; $ownertable .= ""; if ($local_ccs[$i] eq $enrollvar{'courseowner'}) { $ownertable .= ""; } else { $ownertable .= ""; } $ownertable .= " "; } $ownertable .= "
Owner Name Username Status
$pname{$local_ccs[$i]} $local_ccs[$i] $cc_status{$local_ccs[$i]} Course Coordinator
"; } &print_header($r,$tasklongref,$settings{'description'},\$javascript_validations); $r->print(<

$lt{'aecs'}

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

 

$lt{'caes'}

$lt{'cour'}

$disp_table

 

$lt{'mkch'}

$lt{'ccod'}

$lt{'ccus'}
$lt{'cown'}

$lt{'cous'}

$ownertable
$lt{'deam'}.

$lt{'deus'}.

$krbform
$intform
$locform

 




ENDDOCUMENT &print_footer($r); } sub modify_course { my ($r,$tasklongref,$typeref) = @_; my $dom = $ENV{'user.domain'}; my $crs = $ENV{'form.course'}; my %settings = &Apache::lonnet::get('environment',['internal.courseowner','internal.coursecode','internal.authtype','internal.autharg','internal.sectionnums','internal.crosslistngs','description'],$dom,$crs); my %currattr = (); my %newattr = (); my %cenv = (); my $response; my $chgresponse; my $nochgresponse; my $warning; my $reply; my @changes = (); my @nochanges = (); my @sections = (); my @xlists = (); my $changecode = 0; my $changeowner = 0; unless ($settings{'internal.sectionnums'} eq'') { if ($settings{'internal.sectionnums'} =~ m/,/) { @sections = split/,/,$settings{'internal.sectionnums'}; } else { $sections[0] = $settings{'internal.sectionnums'}; } } unless ($settings{'internal.crosslistings'} eq'') { if ($settings{'internal.crosslistings'} =~ m/,/) { @xlists = split/,/,$settings{'internal.crosslistings'}; } else { $xlists[0] = $settings{'internal.crosslistings'}; } } my @params = ('courseowner','coursecode','authtype','autharg'); foreach (@params) { my $attr = 'internal.'.$_; $currattr{$_} = $settings{$attr}; } 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'}; } elsif ($ENV{'form.login'} eq 'int') { $newattr{'authtype'} ='internal'; if ((defined($ENV{'form.intarg'})) && ($ENV{'form.intarg'})) { $newattr{'autharg'} = $ENV{'form.intarg'}; } } elsif ($ENV{'form.login'} eq 'loc') { $newattr{'authtype'} = 'localauth'; if ((defined($ENV{'form.locarg'})) && ($ENV{'form.locarg'})) { $newattr{'autharg'} = $ENV{'form.locarg'}; } } if ( $newattr{'authtype'}=~ /^krb/) { if ($newattr{'autharg'} eq '') { $warning = qq(''. &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').'

'); } } 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.coursecode'}) ) { $newattr{'coursecode'}=$ENV{'form.coursecode'}; unless ( $newattr{'coursecode'} eq $currattr{'coursecode'} ) { $changecode = 1; } } foreach (@params) { if ($currattr{$_} eq $newattr{$_}) { push @nochanges, $_; } else { my $attr = 'internal.'.$_; $cenv{$attr} = $newattr{$_}; push @changes, $_; } } if (@changes > 0) { $chgresponse = "The following automated enrollment parameters have been changed:


"; } unless ($warning eq '') { $warning = "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:

".$warning; } if ($response eq '') { $reply = $chgresponse.$nochgresponse.$warning; } else { $reply = $response; } &print_header($r,$tasklongref,$description); $r->print(" '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 ( ($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'}; $page .= "-> ".$$tasklongref{'display'}." -> $$tasklongref{$action} "; } else { $page .= " -> ".$$tasklongref{$action}.""; } } $r->print(" "); if ($action eq 'display') { $r->print(" "); } $r->print(<The LearningOnline Network with CAPA $bodytag
$reply
$lt{'main'} -> $page
$description  
ENDTHIS } sub print_footer { my $r = shift; $r->print(< ENDBASE } sub handler { my $r = shift; if ($r->header_only) { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; return OK; } if (&Apache::lonnet::allowed('ccc',$ENV{'request.role.domain'})) { &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['action','course']); my $dom = $ENV{'user.domain'}; my %longtype = ( 'authtype' => 'Default authentication method', 'autharg' => 'Default authentication parameter', 'autoadds' => 'Automated adds', 'autodrops' => 'Automated drops', 'autostart' => 'Date of first enrollment', 'autoend' => 'Date of last enrollment', 'coursecode' => 'Official course code', 'courseowner' => "Username of course owner (\@$dom)", 'notifylist' => 'Course Coordinators to be notified of enrollment changes', 'sectionnums' => 'Course section number(:groupID)', 'crosslistings' => 'Crosslisted class(:groupID)', ); my %tasklong = ( 'display' => 'View/modify settings', 'process' => 'Results of changes', ); if ($ENV{'form.action'} eq 'process') { &modify_course($r,\%tasklong,\%longtype); } elsif ($ENV{'form.action'} eq 'display') { &print_course_modification_page($r,\%tasklong,\%longtype); } else { &print_course_selection_page($r,\%tasklong); } } else { $ENV{'user.error.msg'}= "/adm/createcourse:ccc:0:0:Cannot modify course settings"; return HTTP_NOT_ACCEPTABLE; } return OK; } 1; __END__