--- loncom/interface/Attic/londropadd.pm 2005/06/03 16:27:26 1.130
+++ loncom/interface/Attic/londropadd.pm 2007/07/17 21:24:17 1.163
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.130 2005/06/03 16:27:26 www Exp $
+# $Id: londropadd.pm,v 1.163 2007/07/17 21:24:17 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -39,19 +39,15 @@ use Apache::Constants qw(:common :http R
use Spreadsheet::WriteExcel;
use Apache::lonstathelpers();
use Apache::lonlocal;
+use Apache::longroup;
+use LONCAPA();
###############################################################
###############################################################
sub header {
- my $html=&Apache::lonxml::xmlbegin();
- my $bodytag=&Apache::loncommon::bodytag('Enrollment Manager');
- my $title = &mt('LON-CAPA Enrollment Manager');
+ my $start_page=&Apache::loncommon::start_page('Enrollment Manager');
return(<
-$title
-
-$bodytag
+$start_page
\n";
+ "\n";
$Str .= "".&mt('Student Number')." \n";
- $Str .= "\n".' ';
+ $Str .= "
\n".' ';
$Str .= &mt('Disable ID/Student Number Safeguard and Force Change '.
'of Conflicting IDs (only do if you know what you are doing)').
- "\n
\n";
- $Str .= ' \n
\n";
+ $Str .= ' '." \n";
$Str .= &mt('Note: for large courses, this operation may be time '.
'consuming');
@@ -686,7 +713,7 @@ sub print_upload_manager_form {
['lname',&mt('Last Name'), $env{'form.lname_choice'}],
['gen', &mt('Generation'), $env{'form.gen_choice'}],
['id', &mt('ID/Student Number'),$env{'form.id_choice'}],
- ['sec', &mt('Group/Section'), $env{'form.sec_choice'}],
+ ['sec', &mt('Section'), $env{'form.sec_choice'}],
['ipwd', &mt('Initial Password'),$env{'form.ipwd_choice'}],
['email',&mt('EMail Address'), $env{'form.email_choice'}]);
if ($env{'form.upfile_associate'} eq 'reverse') {
@@ -725,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'));
@@ -791,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 {
@@ -853,16 +885,17 @@ sub date_setting_table {
my ($starttime,$endtime,$mode) = @_;
my ($startform,$endform)=&setup_date_selectors($starttime,$endtime,$mode);
my $dateDefault = ''.
- ' '.
- &mt('make these dates the default for future enrollment');
+ ' '.
+ &mt('make these dates the default for future enrollment').
+ ' ';
if ($mode eq 'create_enrolldates' || $mode eq 'create_defaultdates') {
$dateDefault = ' ';
}
- my $perpetual = ' '.&mt('no ending date').' ';
+ $perpetual.= ' /> '.&mt('no ending date').'';
if ($mode eq 'create_enrolldates') {
$perpetual = ' ';
}
@@ -890,7 +923,8 @@ sub make_dates_default {
$result .= "Set default start and end dates for course ";
#
# Refresh the course environment
- &Apache::lonnet::coursedescription($env{'request.course.id'});
+ &Apache::lonnet::coursedescription($env{'request.course.id'},
+ {'freshen_cache' => 1});
} else {
$result .= &mt('Unable to set default dates for course').":".$put_result.
' ';
@@ -916,11 +950,11 @@ sub get_student_username_domain_form {
$lt{'eos'}
-$lt{'usr'}:
+$lt{'usr'} :
-$lt{'dom'}:
+$lt{'dom'} :
$domform
-
+
@@ -937,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;
@@ -966,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 = ''."\n".
'default '."\n";
while (my ($servername,$serverdescription) = each (%servers)) {
@@ -989,19 +1021,19 @@ sub print_enroll_single_student_form {
);
my $authhelp=&Apache::loncommon::help_open_topic('Auth_Options');
$user_data_html = <$lt{'udf'} $username\@$domain
+$lt{'udf'} $username:$domain
$lt{'pswd'}
@@ -1028,29 +1060,19 @@ END
'mail' => "Email Address",
);
$user_data_html = <$lt{'udf'} $username\@$domain
+$lt{'udf'} $username:$domain
END
}
@@ -1058,7 +1080,7 @@ END
# Print it all out
my %lt=&Apache::lonlocal::texthash(
'cd' => "Course Data",
- 'gs' => "Group/Section",
+ 'gs' => "Section",
'idsn' => "ID/Student Number",
'disn' => "Disable ID/Student Number Safeguard and Force Change of Conflicting IDs (only do if you know what you are doing)",
'eas' => "Enroll as student",
@@ -1069,7 +1091,7 @@ END
+ ');
+ }
$r->print("
-
+".&Apache::loncommon::start_data_table()."
");
if ($mode eq 'autoenroll') {
@@ -1294,9 +1347,28 @@ END
$lt{'start'}
$lt{'end'}
+
+ $lt{'grp'}
+
+ $lt{'email'}
-
END
+ if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
+ my %photo_options = &Apache::lonlocal::texthash(
+ 'on' => 'Show',
+ 'off' => 'Hide',
+ );
+ my $photochg = 'on';
+ if ($displayphotos eq 'on') {
+ $photochg = 'off';
+ }
+ $r->print(' '."\n".' '.
+ ''.
+ $photo_options{$photochg}.' '.$lt{'photo'}."\n".
+ ' '."\n");
+ }
+ $r->print(" \n");
} elsif ($mode eq 'csv') {
#
# Open a file
@@ -1315,16 +1387,22 @@ END
if($statusmode eq 'Expired') {
print $CSVfile '"'.&mt('Students with expired roles').'"'."\n";
}
+ if($statusmode eq 'Future') {
+ print $CSVfile '"'.&mt('Students with future roles').'"'."\n";
+ }
if ($statusmode eq 'Any') {
print $CSVfile '"'.join('","',map {
&Apache::loncommon::csv_translate(&mt($_))
} ("username","domain","ID","student name",
- "section","start date","end date","status")).'"'."\n";
+ "section","start date","end date","status",
+ "active groups","email address"))
+ .'"'."\n";
} else {
print $CSVfile '"'.join('","',map {
&Apache::loncommon::csv_translate(&mt($_))
} ("username","domain","ID","student name",
- "section","start date","end date")).'"'."\n";
+ "section","start date","end date",
+ "active groups","email address")).'"'."\n";
}
} elsif ($mode eq 'excel') {
# Create the excel spreadsheet
@@ -1339,7 +1417,8 @@ END
#
$excel_sheet->write($row++,0,["username","domain","ID",
"student name","section",
- "start date","end date","status"],
+ "start date","end date","status",
+ "active groups","email address"],
$format->{'bold'});
}
#
@@ -1349,6 +1428,7 @@ END
foreach (@$keylist) {
$index{$_} = $i++;
}
+ $index{'groups'} = scalar(@{$keylist});
my $index = $index{$sortby};
my $second = $index{'username'};
my $third = $index{'domain'};
@@ -1366,16 +1446,32 @@ END
my $lockcount = 0;
foreach my $student (@Sorted_Students) {
my $sdata = $classlist->{$student};
+ my $groups = $classgroups->{$student};
my $username = $sdata->[$index{'username'}];
my $domain = $sdata->[$index{'domain'}];
my $section = $sdata->[$index{'section'}];
+ my $active_groups;
+ if (ref($groups->{active}) eq 'HASH') {
+ $active_groups = join(', ',keys(%{$groups->{'active'}}));
+ }
my $name = $sdata->[$index{'fullname'}];
my $id = $sdata->[$index{'id'}];
my $status = $sdata->[$index{'status'}];
+ next if (($statusmode ne 'Any') && ($status ne $statusmode));
my $start = $sdata->[$index{'start'}];
my $end = $sdata->[$index{'end'}];
my $type = $sdata->[$index{'type'}];
- next if (($statusmode ne 'Any') && ($status ne $statusmode));
+
+ my %emails = &Apache::loncommon::getemails($username,$domain);
+ my $email;
+ foreach my $type ('critnotification', 'permanentemail',
+ 'notification') {
+ if ($emails{$type} =~ /\S/) {
+ $email = $emails{$type};
+ last;
+ }
+ }
+
if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
if (! defined($start) || $start == 0) {
$start = &mt('none');
@@ -1387,22 +1483,22 @@ END
} else {
$end = &Apache::lonlocal::locallocaltime($end);
}
- $r->print("\n ");
+ $r->print(&Apache::loncommon::start_data_table_row());
if ($mode eq 'autoenroll') {
my $lockedtype = $sdata->[$index{'lockedtype'}];
$studentcount++;
my $cellentry;
if ($type eq 'auto') {
- $cellentry = ''.&mt('auto').' Change';
+ $cellentry = ''.&mt('auto').' Change ';
$autocount ++;
} else {
- $cellentry = ''.&mt('manual').' Change';
+ $cellentry = '';
@@ -1434,8 +1530,23 @@ END
$section
$start
$end
-
+ $active_groups
+ $email
END
+ if ($env{'course.'.$env{'request.course.id'}.
+ '.internal.showphoto'}) {
+ if ($displayphotos eq 'on') {
+ my $imgurl =
+ &Apache::lonnet::retrievestudentphoto($domain,
+ $username,'gif',
+ 'thumbnail');
+
+ $r->print(' ');
+ } else {
+ $r->print(' ');
+ }
+ }
+ $r->print(&Apache::loncommon::end_data_table_row());
} elsif ($mode eq 'csv') {
next if (! defined($CSVfile));
# no need to bother with $linkto
@@ -1456,6 +1567,8 @@ END
if ($statusmode eq 'Any') {
push @line,&Apache::loncommon::csv_translate($status);
}
+ push @line,&Apache::loncommon::csv_translate($active_groups);
+ push @line,&Apache::loncommon::csv_translate($email);
print $CSVfile '"'.join('","',@line).'"'."\n";
} elsif ($mode eq 'excel') {
$excel_sheet->write($row,0,[$username,$domain,$id,
@@ -1471,11 +1584,13 @@ END
}
}
$excel_sheet->write($row,$col++,$status);
+ $excel_sheet->write($row,$col++,$active_groups);
+ $excel_sheet->write($row,$col++,$email);
$row++;
}
}
if ($mode eq 'view' || $mode eq 'html' || $mode eq 'autoenroll') {
- $r->print('
');
+ $r->print(&Apache::loncommon::end_data_table().' ');
} elsif ($mode eq 'excel') {
$excel_workbook->close();
$r->print(''.
@@ -1515,7 +1630,7 @@ sub print_modify_student_form {
''.
&mt('Unable to retrieve environment data for').' '.$sname.
&mt('in domain').' '.$sdom.'
'.
- &mt('Please contact your LON-CAPA administrator regarding this situation.').'