--- loncom/interface/lonpopulate.pm 2005/11/04 15:03:29 1.28 +++ loncom/interface/lonpopulate.pm 2006/02/07 22:15:56 1.36 @@ -1,5 +1,5 @@ # automated enrollment configuration handler -# $Id: lonpopulate.pm,v 1.28 2005/11/04 15:03:29 albertel Exp $ +# $Id: lonpopulate.pm,v 1.36 2006/02/07 22:15:56 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -312,7 +312,7 @@ sub print_main_frame { Use "Section settings" to make changes to the choice of sections included for enrollment in your LON-CAPA course.   - Use "Student photos" to enable or disable automatic upload of student photos to your course. + Use "Student photos settings" to enable or disable automatic import of photos for registered students in your course.   @@ -320,6 +320,10 @@ sub print_main_frame {   + Use "Update student photos" to import your institution's most current digital photos for registered students in your course. + + +   Use "View students and change type" to display the current course roster, and (optionally) change enrollment type for selected students from 'auto' to 'manual' and vice versa. @@ -485,6 +489,7 @@ ENDTWO ENDTWO } elsif ($action eq "notify") { + my $notifycount = 0; my @notified = split(/,/,$enrollvar{notifylist}); foreach (@notified) { unless ($_ eq '') { $notifycount ++; } @@ -566,7 +571,7 @@ ENDTWO $notifystate{$viewer} = 0; } - my $notifyshow = join(' ',@ccs); + my $notifyshow = @ccs; if (@ccs > 0) { @ccs = sort @ccs; @@ -636,7 +641,7 @@ ENDTWO if ($enrollvar{crosslistings} ne '') { @xlists = split(/,/,$enrollvar{crosslistings}); } - my $cross_str = join(' ',@xlists); + my $cross_str = @xlists; $r->print("

@@ -663,7 +668,7 @@ ENDTWO for (my $i=0; $i<@xlists; $i++) { my $xl = ' '; my $gp = ' '; - if ($xlists[$i] =~ /(\w+):?(.*)$/) { + if ($xlists[$i] =~ /^([^:]+):?(.*)$/) { $xl = $1; $gp = $2; } @@ -725,7 +730,7 @@ ENDTWO } } if (@sections > 0) { - my $secshow = join(' ',@sections); + my $secshow = @sections; $r->print("
@@ -791,7 +796,7 @@ your changes. @@ -882,29 +887,87 @@ your changes. No "); } - $r->print(" + $r->print(' + '); + my ($result,$perm_reqd)=&Apache::lonnet::auto_photo_permission($crs,$dom); + my $can_enable = 1; + my $institution = $Apache::lonnet::domaindescription{$dom}; + if ($result eq 'ok') { + if ($perm_reqd eq 'yes') { + if (!($enrollvar{'photopermission'} eq 'yes')) { + $can_enable = 0; + } else { + if ($env{'user.name'} eq $enrollvar{'courseowner'}) { + $r->print(' + + + + '); + } + } + } + } else { + $r->print(' + + + + + '); + return; + } + if ($can_enable) { + $r->print(' +'); + } else { + if ($env{'user.name'} eq $enrollvar{'courseowner'}) { + $r->print(' + + + + '); + } else { + my ($ownername,$owneremail) = &get_ownerinfo($dom, + $enrollvar{'courseowner'}); + $r->print(' + + + + + '); + return; + } + } + $r->print('   -
$$tasktitleref{$action}
"); if (@currsections) { - my $secshow = join(' ',@currsections); + my $secshow = @currsections; $r->print(" Currently, this LON-CAPA course incorporates enrollment from $secshow sections. Students enrolling in any of these course sections will be automatically added to the class roster for the course, if you have chosen to enable a nightly automated enrollment update. For each section, uncheck the checkbox if you want registered students in that section to cease being included in the student roster for LON-CAPA course: $realm ($enrollvar{coursecode}); otherwise leave it checked. If you want to change the section/group designation used for this section in LON-CAPA, delete the current value in the LON-CAPA section/groupID textbox and enter the new value. If you wish to add new course section, enter the number of new sections to add in the textbox at the bottom of the page. You will provide information about each of the new sections on a subsequent page. Click 'Go' to store your changes.
'. +&mt('Previously the owner of this course agreed to the conditions of use of digital student photos required by [_1].', $institution).'
'.&mt('As a result Course Coordinators can choose to automatically import student photos into this course.').'
+
'. +&mt('There was a problem determining whether course owner permission is required in order for a course coordinator to have access to student photos in this domain.').' '.&mt('As a result you will not be able to configure access to student photos at this time').'

+
- -Note: if you enable automatic import of student photos, your course will automatically have access to photos stored by your institution for all officially registered students, via a conduit established by your LON-CAPA domain coordinator. + '. +&mt('Note: if you enable automatic import of student photos, your course will automatically have access to photos stored by your institution for officially registered students, via a conduit established by your LON-CAPA domain coordinator.').'
'. +&mt('[_1] requires a course owner to indicate acceptance of conditions of use of digital student photos before enabling automatic import into a course. If you choose to enable import of photos you will be prompted for your agreement on the next page.',$institution).' +
'. +&mt('The policies of your institution [_1] require that the course owner [_2] must indicate acceptance of the conditions of use of digital photos of registered students, before they may be made available for use in a course.',$institution,$ownername).'

'.&mt('Please direct the course owner (e-mail: [_1]) to visit the "Student photos" page in the Automated Enrollment Manager to indicate acceptance of these conditions of use',$owneremail).'

+
- + +
- - + + - "); + '); } elsif ($action eq "updatenow") { $r->print("

@@ -951,6 +1014,29 @@ Note: Any students previously added manu
"); + } elsif ($action eq 'updatephotos') { + $r->print(" + + + + + +
$$tasktitleref{$action} +
"); + if ($enrollvar{'showphotos'}) { + my ($update,$commentary) = &Apache::lonnet::auto_photochoice($crs, + $dom); + $r->print('
'.$commentary.'

+
+ + + +
'); + } else { + $r->print('Update of photos is unavailable, as import of student photos is currently disabled.
Enable this first via: '.$$tasktitleref{'photos'}.''); + } + $r->print('
 
'); } elsif ($action eq 'viewclass') { $r->print("

@@ -2023,39 +2109,276 @@ sub print_sections_response () { return; } -sub print_photos_response () { +sub photo_permission { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; - my %settings = &Apache::lonnet::get('environment',['internal.showphotos'],$dom,$crs); - my $currphotos = $settings{'internal.showphotos'}; - my $showphotos = ''; - if ( exists($env{'form.showphotos'}) ) { - $showphotos=$env{'form.showphotos'}; + my %settings = &Apache::lonnet::get('environment', + ['internal.courseowner', + 'internal.photopermission', + 'internal.showphotos'], + $dom,$crs); + my ($showphotos,$response); + if (exists($env{'form.cancel_agreement'})) { + if ($env{'user.name'} eq $settings{'internal.courseowner'}) { + my %cenv = ( + 'internal.photopermission' => 'no', + ); + my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); + if ($reply !~ /^ok$/) { + $response = &mt('There was a problem processing the record of your agreement to the conditions of use. Settings for this course have been left unchanged.').'
'."\n"; + &print_reply($r,$response,$$tasktitleref{$action}); + } else { + &print_photos_response($r,$realm,$dom,$crs,$action, + $tasktitleref,$showphotos,'no',\%cenv); + } + return; + } + } + if (exists($env{'form.showphotos'})) { + $showphotos=$env{'form.showphotos'}; + } + if ($showphotos) { + if ($env{'form.photopermission'}) { + my %cenv = ( + 'internal.photopermission' => $env{'form.photopermission'}, + ); + my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); + if ($reply !~ /^ok$/) { + $response = &mt('There was a problem processing the record of your agreement to the conditions of use. Settings for this course have been left unchanged.').'
'."\n"; + } else { + &print_photos_response($r,$realm,$dom,$crs,$action, + $tasktitleref,$showphotos, + $env{'form.photopermission'},\%cenv); + } + } else { + my ($result,$perm_reqd,$conditions) = + &Apache::lonnet::auto_photo_permission($crs,$dom); + my $permcheck; + if ($result eq 'ok') { + if ($perm_reqd eq 'yes') { + if ($settings{'internal.photopermission'} eq 'yes') { + &print_photos_response($r,$realm,$dom,$crs,$action, + $tasktitleref,$showphotos); + } else { + return(&print_photo_agreement($r,$realm,$dom,$crs, + $action,$tasktitleref, + $conditions, + $settings{'internal.courseowner'})); + } + } elsif ($perm_reqd eq 'no') { + &print_photos_response($r,$realm,$dom,$crs,$action, + $tasktitleref,$showphotos); + } else { + $permcheck = 'fail'; + } + } else { + $permcheck = 'fail'; + } + if ($permcheck eq 'fail') { + my $response = &mt('There was a problem processing your requested change, because it could not be determined whether course owner permission is required in order for a course coordinator to have access to student photos in this domain.').' '.&mt('The student photo import setting for this course has been left unchanged.').'
'; + &print_reply($r,$response,$$tasktitleref{$action}); + } + } + } else { + &print_photos_response($r,$realm,$dom,$crs,$action,$tasktitleref); } - + return; +} + +sub print_photo_agreement { + my ($r,$realm,$dom,$crs,$action,$tasktitleref,$conditions,$courseowner)=@_; + my $response; + my $institution = $Apache::lonnet::domaindescription{$dom}; + if ($env{'user.name'} eq $courseowner) { + $response = ' + + + + + + +
Use of student photos
'."\n". + &mt('Acceptance by the course owner of the conditions of use of photos is currently [_1] set.','not').'
'.&mt('Please indicate your acceptance of the conditions of use of digital photos of registered students in courses at [_1].',$institution).' +
+ + + + + + + +
+ +
+ + + +
+ + + + +
+'; + } else { + my ($ownername,$owneremail) = &get_oenerinfo($dom,$courseowner); + $response = &mt('The policies of your institution [_1] require that the course owner [_2] must indicate acceptance of the conditions of use of digital photos of registered students, before they may be made available for use in a course.',$institution,$ownername).'

'.&mt('Please direct the course owner (e-mail: [_1]) to visit the "Student photos" page in the Automated Enrollment Manager to indicate acceptance of these conditions of use',$owneremail); + } + &print_reply($r,$response,$$tasktitleref{$action}); +} + +sub print_photos_response { + my ($r,$realm,$dom,$crs,$action,$tasktitleref,$showphotos,$photopermission, + $permissionenv)=@_; + my %newenv; + if (defined($permissionenv)) { + foreach my $key (keys(%{$permissionenv})) { + if (exists($env{'request.course.id'})) { + $newenv{$env{'request.course.id'}.'.'.$key} = + $$permissionenv{$key}; + } + } + } + my %settings = &Apache::lonnet::get('environment',['internal.showphotos'], + $dom,$crs); + my $currphotos = $settings{'internal.showphotos'}; my $response = ""; + if (defined($photopermission)) { + if ($photopermission eq 'yes') { + $response = &mt('Acceptance of photo use policy recorded.').'
'."\n"; + } else { + $response = &mt('Non-acceptance of photo use policy recorded.').'
'."\n"; + $showphotos = 0; + } + } my %cenv = ('internal.showphotos' => $showphotos); my $reply = &Apache::lonnet::put('environment',\%cenv,$dom,$crs); if ($reply !~ /^ok$/) { - $response = "There was a problem processing your requested change. The student photo import setting for this course has been left unchanged.
"; + $response .= "There was a problem processing your requested change. The student photo retrieval setting for this course has been left unchanged.
"; } else { if ($showphotos) { if ($currphotos) { - $response = "Retrieval of student photos is still enabled
"; + $response .= "Retrieval of student photos is still enabled.
"; } else { - $response = "Retrieval of student photos in now enabled
"; + $response .= "Retrieval of student photos in now enabled.
"; + my ($update,$commentary) = + &Apache::lonnet::auto_photochoice($crs,$dom); + if ($update) { + $response .= '
'.$commentary.'

+
+ + + +
'; + } } } else { if ($currphotos) { - $response = "Retrieval of student photos is now disabled
"; + $response .= "Retrieval of student photos is now disabled.
"; } else { - $response = "Retrieval of student photos is still disabled
"; + $response .= "Retrieval of student photos is still disabled.
"; } } + foreach my $key (keys(%cenv)) { + if (exists($env{'request.course.id'})) { + $newenv{'course.'.$env{'request.course.id'}.'.'.$key} = + $cenv{$key}; + } + } + } + if (keys(%newenv) > 0) { + &Apache::lonnet::appenv(%newenv); } &print_reply($r,$response,$$tasktitleref{$action}); return; } +sub print_photoupdate_response { + my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; + my $response; + my %changes; + my %lt = &LONCAPA::Enrollment::photo_response_types(); + my %settings = &Apache::lonnet::get('environment', + ['internal.coursecode', + 'internal.sectionnums', + 'internal.crosslistings'], + $dom,$crs); + my @allcourses = (); + my %LC_code; + my %affiliates; + my $outcome; + &get_institutional_codes(\%settings,,\@allcourses,\%LC_code); + if (@allcourses > 0) { + @{$affiliates{$crs}} = @allcourses; + $outcome = &Apache::lonnet::auto_photoupdate(\%affiliates,$dom,$crs,\%changes); + unless ($outcome eq 'ok') { + &Apache::lonnet::logthis("lonpopulate::print_photoupdate_response". + "failed to update student photos". + " for ".$crs."\@".$dom." by ". + $env{'user.name'}." \@ ".$env{'user.domain'}. + ": ".$outcome); + } + if ($outcome eq 'ok') { + if (keys(%changes) > 0) { + $response = &mt('Update of photos for registered students resulted in the following ').':
+'; + foreach my $type (sort(keys(%changes))) { + my @usernames = sort(split(/\&/,$changes{$type})); + my $count = @usernames; + $response .= ''.&mt('For [_1] students, photos ', + $count).$lt{$type}.'
'; + } + } else { + $response = &mt('No updates of photos of registered students occurred'). + '
'; + } + } else { + $response = "There was a problem updating student photos for registered students in this course.
"; + } + } else { + $response = "No institutional course sections are currently associated with this course so there are no registered students for whom photos can be imported/updated"; + } + &print_reply($r,$response,$$tasktitleref{$action}); + return; +} + +sub get_ownerinfo { + my ($dom,$owner) = @_; + my ($ownername,$owneremail); + if ($owner) { + $ownername=&Apache::loncommon::plainname($owner,$dom,'firstname'); + my %ownerinfo = &Apache::lonnet::get('environment',['permanentemail'], + $dom,$owner); + $owneremail = $ownerinfo{'permanentemail'}; + } + return ($ownername,$owneremail); +} + sub print_update_result () { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; my $response = ''; @@ -2068,11 +2391,12 @@ sub print_update_result () { my %LC_code = (); my $logmsg = ''; my $newusermsg = ''; - - my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg'],$dom,$crs); + my %phototypes = (); + my %settings = &Apache::lonnet::get('environment',['internal.coursecode','internal.sectionnums','internal.crosslistings','internal.authtype','internal.autharg','internal.showphotos'],$dom,$crs); my $coursecode = $settings{'internal.coursecode'}; my $authtype = $settings{'internal.authtype'}; my $autharg = $settings{'internal.autharg'}; + my $showphotos = $settings{'internal.showphotos'}; my ($startaccess,$endaccess) = &get_dates_from_form(); if ( exists($env{'form.updateadds'}) ) { $updateadds = $env{'form.updateadds'}; @@ -2089,42 +2413,7 @@ sub print_update_result () { } elsif ($coursecode eq '') { $response = "There was a problem retrieving the course code for this LON-CAPA course. An update of the class roster has not been carried out, and enrollment remains unchanged"; } else { -# Get complete list of course sections to update - my @currsections = (); - my @currxlists = (); - - if ($settings{'internal.sectionnums'} ne '') { - @currsections = split(/,/,$settings{'internal.sectionnums'}); - } - - if ($settings{'internal.crosslistings'} ne '') { - @currxlists = split(/,/,$settings{'internal.crosslistings'}); - } - - if (@currxlists > 0) { - foreach (@currxlists) { - if (m/^(\w+):(\w*)$/) { - unless (grep/^$1$/,@allcourses) { - push @allcourses,$1; - $LC_code{$1} = $2; - } - } - } - } - - if (@currsections > 0) { - foreach (@currsections) { - if (m/^(\w+):(\w*)$/) { - my $sec = $coursecode.$1; - my $gp = $2; - unless (grep/^$sec$/,@allcourses) { - push @allcourses,$sec; - $LC_code{$sec} = $gp; - } - } - } - } - + &get_institutional_codes(\%settings,\@allcourses,\%LC_code); if (@allcourses > 0) { @{$affiliates{$crs}} = @allcourses; my $outcome = &Apache::lonnet::fetch_enrollment_query('updatenow',\%affiliates,\%reply,$dom,$crs); @@ -2136,7 +2425,7 @@ sub print_update_result () { ": ".$outcome); } if ($reply{$crs} > 0) { - ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow"); + ($changecount,$response) = &LONCAPA::Enrollment::update_LC($dom,$crs,$updateadds,$updatedrops,$startaccess,$endaccess,$authtype,$autharg,\@allcourses,\%LC_code,\$logmsg,\$newusermsg,"updatenow",\%phototypes); } else { $response = "There was a problem retrieving institutional class list data for the course sections and crosslisted courses which contribute enrollment to this course. No updates have been carried out, and the roster remains unchanged."; } @@ -2158,6 +2447,48 @@ sub print_update_result () { return; } +sub get_institutional_codes { + my ($settings,$allcourses,$LC_code) = @_; +# Get complete list of course sections to update + my @currsections = (); + my @currxlists = (); + my $coursecode = $$settings{'internal.coursecode'}; + + if ($$settings{'internal.sectionnums'} ne '') { + @currsections = split(/,/,$$settings{'internal.sectionnums'}); + } + + if ($$settings{'internal.crosslistings'} ne '') { + @currxlists = split(/,/,$$settings{'internal.crosslistings'}); + } + + if (@currxlists > 0) { + foreach (@currxlists) { + if (m/^([^:]+):(\w*)$/) { + unless (grep/^$1$/,@{$allcourses}) { + push @{$allcourses},$1; + $$LC_code{$1} = $2; + } + } + } + } + + if (@currsections > 0) { + foreach (@currsections) { + if (m/^(\w+):(\w*)$/) { + my $sec = $coursecode.$1; + my $gp = $2; + unless (grep/^$sec$/,@{$allcourses}) { + push @{$allcourses},$sec; + $$LC_code{$sec} = $gp; + } + } + } + } + return; +} + + sub print_viewclass_response { my ($r,$realm,$dom,$crs,$action,$tasktitleref) = @_; my $response; @@ -2477,13 +2808,13 @@ sub handler { if (! (($env{'request.course.fn'}) && (&Apache::lonnet::allowed('cst',$env{'request.course.id'})))) { # Not in a course, or not allowed to modify parms $env{'user.error.msg'}="/adm/populate:cst:0:0:Cannot drop or add students"; - return HTTP_NOT_ACCEPTABLE; + return HTTP_NOT_ACCEPTABLE; } # Start page &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; - my @tasks = ("information","chgsettings","setdates","setaccess","notify","crosslist","sections","photos","updatenow","viewclass"); + my @tasks = ("information","chgsettings","setdates","setaccess","notify","crosslist","sections","photos","updatenow","updatephotos","viewclass"); my %tasklong = ( information => "Task information", @@ -2493,7 +2824,8 @@ sub handler { notify => "Notification of changes", crosslist => "Change crosslistings", sections => "Section settings", - photos => "Student photos", + photos => "Student photo settings", + updatephotos => "Update student photos", updatenow => "Update roster now", newcross => "Add crosslistings", newsections => "Add sections", @@ -2507,7 +2839,8 @@ sub handler { notify => "Notification of enrollment changes", crosslist => "Changes to crosslistings", sections => "Changes to section settings", - photos => "Automatic import of student photos", + photos => "Student photo settings", + updatephotos => "Update student photos", updatenow => "Immediate course roster update", newcross => "Adding new crosslisted courses", newsections => "Adding new course sections", @@ -2591,7 +2924,13 @@ sub handler { } elsif ($action eq "updatenow") { &print_update_result($r,$realm,$dom,$crs,$action,\%tasktitle); } elsif ($action eq "photos") { - &print_photos_response($r,$realm,$dom,$crs,$action,\%tasktitle); + if ($state eq "photoupdate") { + &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle); + } else { + &photo_permission($r,$realm,$dom,$crs,$action,\%tasktitle); + } + } elsif ($action eq "updatephotos") { + &print_photoupdate_response($r,$realm,$dom,$crs,$action,\%tasktitle); } elsif ($action eq "newcross") { &print_crosslistings_response($r,$realm,$dom,$crs,$action,\%tasktitle); } elsif ($action eq "newsections") {