--- loncom/interface/Attic/londropadd.pm 2006/11/22 22:53:41 1.148 +++ loncom/interface/Attic/londropadd.pm 2007/07/02 21:12:06 1.162 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to drop and add students in courses # -# $Id: londropadd.pm,v 1.148 2006/11/22 22:53:41 banghart Exp $ +# $Id: londropadd.pm,v 1.162 2007/07/02 21:12:06 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,6 +40,7 @@ use Spreadsheet::WriteExcel; use Apache::lonstathelpers(); use Apache::lonlocal; use Apache::longroup; +use LONCAPA(); ############################################################### ############################################################### @@ -60,8 +61,8 @@ sub modifystudent { # if $csec is undefined, drop the student from all the courses matching # this one. If $csec is defined, drop them from all other sections of # this course and add them to section $csec - $courseid=~s/\_/\//g; - $courseid=~s/^(\w)/\/$1/; + my $cdom = $env{'course.'.$courseid.'.domain'}; + my $cnum = $env{'course.'.$courseid.'.num'}; my %roles = &Apache::lonnet::dump('roles',$udom,$unam); my ($tmp) = keys(%roles); # Bail out if we were unable to get the students roles @@ -69,10 +70,10 @@ sub modifystudent { # Go through the roles looking for enrollment in this course my $result = ''; foreach my $course (keys(%roles)) { - if ($course=~/^$courseid(?:\/)*(?:\s+)*(\w+)*\_st$/) { + if ($course=~m{^/\Q$cdom\E/\Q$cnum\E(?:\/)*(?:\s+)*(\w+)*\_st$}) { # We are in this course my $section=$1; - $section='' if ($course eq $courseid.'_st'); + $section='' if ($course eq "/$cdom/$cnum".'_st'); if (defined($csec) && $section eq $csec) { $result .= 'ok:'; } elsif ( ((!$section) && (!$csec)) || ($section ne $csec) ) { @@ -105,7 +106,7 @@ sub domain_form { # Set up domain and server selection forms # # Get the domains - my @domains = &Apache::loncommon::get_domains(); + my @domains = &Apache::lonnet::all_domains(); # build up the menu information to be passed to # &Apache::loncommon::linked_select_forms my %select_menus; @@ -116,7 +117,7 @@ sub domain_form { $select_menus{$dom}->{'default'}= 'default'; $select_menus{$dom}->{'select2'}->{'default'} = 'default'; # Now build up the other items in the second menu - my %servers = &Apache::loncommon::get_library_servers($dom); + my %servers = &Apache::lonnet::get_servers($dom,'library'); foreach my $server (keys(%servers)) { $select_menus{$dom}->{'select2'}->{$server} = "$server $servers{$server}"; @@ -135,7 +136,9 @@ sub print_main_menu { my ($r,$enrl_permission,$view_permission,$grp_manage_permission, $grp_view_permission)=@_; # - my ($cdom,$cnum) = split/_/,$env{'request.course.id'}; + my $cid =$env{'request.course.id'}; + my $cdom=$env{'course.'.$cid.'.domain'}; + my $cnum=$env{'course.'.$cid.'.num'}; my @menu = ( { text => 'Upload a class list', @@ -177,11 +180,16 @@ sub print_main_menu { permission => $grp_manage_permission, url => '/adm/coursegroups?refpage=enrl&action=modify', }, -# { text => 'Delete an existing group', -# help => 'Course_Delete_Group', -# permission => $grp_manage_permission, -# url => '/adm/coursegroups?refpage=enrl&action=delete', -# }, + { text => 'Delete an existing group', + help => 'Course_Delete_Group', + permission => $grp_manage_permission, + url => '/adm/coursegroups?refpage=enrl&action=delete', + }, + { text => 'Re-enable a deleted group', + help => 'Course_Reenable_Group', + permission => $grp_manage_permission, + url => '/adm/coursegroups?refpage=enrl&action=reenable', + }, { text => 'Enter an existing group', help => 'Course_Display_Group', permission => $grp_view_permission, @@ -250,7 +258,7 @@ sub print_upload_manager_header { # my $javascript_validations=&javascript_validations('auth',$krbdefdom, $password_choice); - my $checked=(($env{'form.noFirstLine'})?' CHECKED ':''); + my $checked=(($env{'form.noFirstLine'})?' checked="checked" ':''); $r->print('

'.&mt('Uploading Class List')."

\n". "
\n". '

'.&mt('Identify fields')."

\n"); @@ -744,17 +752,21 @@ sub enroll_single_student { } $r->print('

'.&mt('Enrolling Student').'

'); - $r->print('

'.&mt('Enrolling').' '.$env{'form.cuname'}." \@ ". - $env{'form.lcdomain'}.'

'); - if (($env{'form.cuname'})&&($env{'form.cuname'}!~/\W/)&& - ($env{'form.lcdomain'})&&($env{'form.lcdomain'}!~/\W/)) { + $r->print('

'.&mt('Enrolling [_1] : [_2]',$env{'form.cuname'}, + $env{'form.lcdomain'}).'

'); + if (($env{'form.cuname'}) + && ($env{'form.cuname'} + eq &LONCAPA::clean_username($env{'form.cuname'})) + && ($env{'form.lcdomain'}) + && ($env{'form.lcdomain'} + eq &LONCAPA::clean_domain($env{'form.lcdomain'}))) { # Deal with home server selection my $domain=$env{'form.lcdomain'}; my $desiredhost = $env{'form.lcserver'}; if (lc($desiredhost) eq 'default') { $desiredhost = undef; } else { - my %home_servers =&Apache::loncommon::get_library_servers($domain); + my %home_servers =&Apache::lonnet::get_servers($domain,'library'); if (! exists($home_servers{$desiredhost})) { $r->print(''.&mt('Error').':'. &mt('Invalid home server specified')); @@ -810,6 +822,7 @@ sub enroll_single_student { } else { $r->print(&mt('Invalid username or domain')); } + $r->print("

".&mt("Enroll another student")."

"); } sub setup_date_selectors { @@ -873,7 +886,8 @@ sub date_setting_table { my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode); my $dateDefault = ''. ''; + &mt('make these dates the default for future enrollment'). + ''; if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') { $dateDefault = ' '; } @@ -936,11 +950,11 @@ sub get_student_username_domain_form {

$lt{'eos'}

- + - + - + @@ -957,10 +971,8 @@ sub print_enroll_single_student_form { my $r=shift; $r->print("

".&mt('Enroll One Student')."

"); # - my $username = $env{'form.cuname'}; - my $domain = $env{'form.cudomain'}; - $username=~s/\W//gs; - $domain=~s/\W//gs; + my $username = &LONCAPA::clean_username($env{'form.cuname'}); + my $domain = &LONCAPA::clean_domain($env{'form.cudomain'}); my $home = &Apache::lonnet::homeserver($username,$domain); # $new_user flags whether we are creating a new user or using an old one my $new_user = 1; @@ -986,7 +998,7 @@ sub print_enroll_single_student_form { # # Set up domain selection form my $homeserver_form = ''; - my %servers = &Apache::loncommon::get_library_servers($domain); + my %servers = &Apache::lonnet::get_servers($domain,'library'); $homeserver_form = '
$lt{'usr'}:
:
$lt{'dom'}:
: $domform
 
 
- - - - - - - - - + + + + + + + + + - +
$lt{'fn'}:
$lt{'mn'}:
$lt{'ln'}:
$lt{'gen'}:
$lt{'hs'}:
:
:
:
:
: $homeserver_form
$lt{'mail'}:
:

$lt{'pswd'}

@@ -1048,29 +1060,19 @@ END 'mail' => "Email Address", ); $user_data_html = <$lt{'udf'} $username\@$domain +

$lt{'udf'} $username:$domain

- - - - - - - - - - + + + + + + + + + +
$lt{'fn'}: - -
$lt{'mn'}: - -
$lt{'ln'}: - -
$lt{'gen'}: - -
$lt{'mail'}: - -
:
:
:
:
:
END } @@ -1132,20 +1134,19 @@ $user_data_html

$lt{'cd'}

-

$lt{'gs'}: -

-$date_table +

:

+$date_table

$lt{'idsn'}

-$lt{'idsn'}: +:

- +

END return; @@ -1177,7 +1178,7 @@ sub print_html_classlist { } my $status_select = &Apache::lonhtmlcommon::StatusOptions ($env{'form.Status'}); - my $cid=$env{'request.course.id'}; + my $cid =$env{'request.course.id'}; my $cdom=$env{'course.'.$cid.'.domain'}; my $cnum=$env{'course.'.$cid.'.num'}; # @@ -1223,9 +1224,9 @@ sub print_html_classlist { $output_selector .= "\n".$option; } $output_selector .= ''; - $r->print(&mt('Output Format: [_1]',$output_selector).(' 'x3)); + $r->print(''.(' 'x3)); } - $r->print(&mt('Student Status: [_1]',$status_select)."\n"); + $r->print('\n"); $r->print(''. "\n

\n"); # @@ -1687,7 +1688,7 @@ $lt{'odcc'}

$lt{'mef'} $info{'firstname'} $info{'middlename'} -$info{'lastname'} $info{'generation'}, $sname\@$sdom

+$info{'lastname'} $info{'generation'}, $sname:$sdom

$lt{'sn'} @@ -1699,14 +1700,14 @@ $info{'lastname'} $info{'generation'}, $

-$lt{'sid'}: +$lt{'sid'}:

-$lt{'sec'}: +$lt{'sec'}:

$current_date_description

$date_table

@@ -1748,7 +1749,7 @@ sub modify_single_student { $env{'request.course.id'}); my ($tmp) = keys(%old); if ($tmp =~ /^(con_lost|error|no_such_host)/i) { - $r->print(&mt('There was an error determining the environment values for')." $slogin \@ $sdom."); + $r->print(&mt('There was an error determining the environment values for')." $slogin : $sdom."); return; } undef $tmp; @@ -1788,7 +1789,7 @@ sub modify_single_student { 'et' => "End Time", ); $r->print(<$lt{'mdu'} $slogin \@ $sdom +

$lt{'mdu'} $slogin : $sdom

$lt{'si'}

@@ -1848,8 +1849,8 @@ END &mt('The error reported was')." ". $roleresults); &Apache::lonnet::logthis("londropadd:failed attempt to modify student". - " data for ".$slogin." \@ ".$sdom." by ". - $env{'user.name'}." \@ ".$env{'user.domain'}. + " data for ".$slogin." : ".$sdom." by ". + $env{'user.name'}." : ".$env{'user.domain'}. ":".$roleresults); } else { # everything is okay! $r->print(&mt('Student information updated successfully.')."
". @@ -1870,7 +1871,8 @@ END sub get_enrollment_data { my ($sname,$sdomain) = @_; my $courseid = $env{'request.course.id'}; - $courseid =~ s:_:/:g; + my $cdom = $env{'course.'.$courseid.'.domain'}; + my $cnum = $env{'course.'.$courseid.'.num'}; my %roles = &Apache::lonnet::dump('roles',$sdomain,$sname); my ($tmp) = keys(%roles); # Bail out if we were unable to get the students roles @@ -1880,7 +1882,7 @@ sub get_enrollment_data { my $section = ''; my $count = scalar(keys(%roles)); while (my ($course,$role) = each(%roles)) { - if ($course=~ /^\/$courseid\/*\s*(\w+)*_st$/ ) { + if ($course=~m{^/\Q$cdom\E/\Q$cnum\E/*\s*(\w+)*_st$} ) { # # Get active role $section=$1; @@ -2159,7 +2161,7 @@ sub upfile_drop_add { if (lc($desiredhost) eq 'default') { $desiredhost = undef; } else { - my %home_servers = &Apache::loncommon::get_library_servers($domain); + my %home_servers = &Apache::lonnet::get_servers($domain,'library'); if (! exists($home_servers{$desiredhost})) { $r->print(''.&mt('Error').''. &mt('Invalid home server specified')); @@ -2193,7 +2195,8 @@ sub upfile_drop_add { $amode = ''; # This causes the loop below to be skipped } } - unless (($domain=~/\W/) || ($amode eq '')) { + if ( $domain eq &LONCAPA::clean_domain($domain) + && ($amode ne '')) { ####################################### ## Enroll Students ## ####################################### @@ -2227,7 +2230,8 @@ sub upfile_drop_add { $gen=$entries{$fields{'gen'}}; } } - if ($entries{$fields{'username'}}=~/\W/) { + if ($entries{$fields{'username'}} + ne &LONCAPA::clean_username($entries{$fields{'username'}})) { $r->print('
'. &mt('[_1]: Unacceptable username for user [_2] [_3] [_4] [_5]', $entries{$fields{'username'}},$fname,$mname,$lname,$gen).